NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
devmanfrommars@gmx.de Posted via mailing list.
|
Posted: Thu Nov 12, 2009 3:28 pm Post subject: read resultset from a database class |
|
|
i have a class :
public class JDb {
private Connection con = null;
private Statement stmt = null;
public ResultSet rs = null;
public void ConnectDb() {
try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://" + JDbConfig.STRhost +
":" + JDbConfig.STRport + "/" + JDbConfig.STRdatabase + "?" + "user=" +
JDbConfig.STRusername + "&password=" + JDbConfig.STRpassword + "";
con = DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: " +
cE.toString());
}
}
public void makeQuery(String strSQL) {
try {
this.stmt = this.con.createStatement();
this.rs = this.stmt.executeQuery(strSQL);
// rowsEffected = this.stmt.executeUpdate(strSQL);
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.toString());
}
}
}
and i want to access the result in the calling class
public void getConfig() {
String strSQL = "";
JDb db = new JDb();
db.ConnectDb();
strSQL = "SELECT " +
" ckey," +
" cvalue," +
" cdescruption " +
"FROM " +
" config " +
"ORDER BY " +
" ckey";
db.makeQuery(strSQL);
while (db.rs.next()) {
but i get alwys erros o the
while (db.rs.next())
whats wrong?! |
|
| Back to top |
|
 |
bhobiger
Joined: 29 Oct 2009 Posts: 52
|
Posted: Thu Nov 12, 2009 3:48 pm Post subject: Re: read resultset from a database class |
|
|
| devmanfrommars@gmx.de wrote: | but i get alwys erros o the
while (db.rs.next())
whats wrong?! |
Which errors? Does makeQuery() throw any exceptions? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|