NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

read resultset from a database class

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
devmanfrommars@gmx.de
Posted via mailing list.





PostPosted: Thu Nov 12, 2009 3:28 pm    Post subject: read resultset from a database class Reply with quote

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

PostPosted: Thu Nov 12, 2009 3:48 pm    Post subject: Re: read resultset from a database class Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo