I need to get all the entries of a column in a database (mysql server) by using java code. Please find the code below:
public class DBConnection {
private String name = null;
private String path = null;
public void DbValues(){
try {
Class.forName("driver");
Connection con = DriverManager.getConnection(
"jdbc:sqlserver:..",
"username",
"password");
if (!con.isClosed()) {
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select name, path from [testtable].[tbl_details]");
while (rs.next()) {
name = rs.getString("name");
path = rs.getString("path");
}
con.close();
} else
System.out.println("failed");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace(); }
}
public String getName() {
return this.name;
}
public String getPath() {
return this.path;
}
}
//in main class
public class DBTest {
public static void main(String[] args) {
DBConnection dbcon = new DBConnection();
dbcon.DbValues();
String path = dbcon.getPath();
System.out.println("value is .." +path);
}
}
Here it displays only last value of path. Means if it has 20 entry, it will display only 20th value of "path" I need to get all the entries in that particular column. Please help.