| Author |
Putting Database values in JavaBeans
|
Sunil Chandurkar
Ranch Hand
Joined: Jan 09, 2008
Posts: 37
|
|
I have a table called counter in mysql. One field called count datatype integer. Here's the class: <code> public String execute(){ private int number; public void setNumber... public int getNumber... try { Class.forName... Connection con ... Statement stmt ... ResultSet rs = stmt.executeQuery(select*from counter); while (rs.next()) { number = rs.getInt("count"); } catch... } </code> What should I add in the code so that the Javabean number property will hold the integer count retrieved from the database. Thanks
|
 |
Shailesh Chandra
Ranch Hand
Joined: Aug 13, 2004
Posts: 1076
|
|
I am not sure you have posted complete problem. Correct me if I am wrong, the counter table has a column named count as integer type then there would be many count count unless you add something in your where clause. so how do you want to hold them in single variable ? What is your exact problem ? Shailesh
|
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
|
 |
Sunil Chandurkar
Ranch Hand
Joined: Jan 09, 2008
Posts: 37
|
|
Shailesh, I have inserted values for only one row. So the query "select * from count" returns only one row. Thanks Sunil
|
 |
Shailesh Chandra
Ranch Hand
Joined: Aug 13, 2004
Posts: 1076
|
|
Ok, so what is the problem you are facing ? any error ? Shailesh [ September 16, 2008: Message edited by: Shailesh Chandra ]
|
 |
mark walter
Greenhorn
Joined: Jun 20, 2008
Posts: 15
|
|
Is this what you are trying to do? <code> private int number; public void setNumber... public int getNumber... public String execute(){ try { Class.forName... Connection con ... Statement stmt ... ResultSet rs = stmt.executeQuery(select*from counter); while (rs.next()) { this.setNumber(rs.getInt("count")); } catch... } </code>
|
 |
Sunil Chandurkar
Ranch Hand
Joined: Jan 09, 2008
Posts: 37
|
|
Thanks...I found the answer. Just had to call the setter method and pass the rs.getInt("count") as the argument.
|
 |
 |
|
|
subject: Putting Database values in JavaBeans
|
|
|