Results 1 to 5 of 5
Thread: JDBC with Swing question
- 03-17-2011, 06:45 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
JDBC with Swing question
ok hi im pretty new to JDBC i was just wondering if anyone can help with this question i have ok here's the question. i was just wondering is that when you get a resultsset back from the database can you display all the results for that query in the different JLabels. like the first row received back will be display in the first jlabel and the second row received back will be display in the second jlabel and so on...
im sorry if i posted this in the wrong section im only a new member to this website. any help with the question mentioned above would be great thank you.
- 03-17-2011, 06:48 PM #2
Check out camickr's Table from Database
Table From Database « Java Tips Weblog
db
- 03-17-2011, 06:54 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
ya i seen using Jtables to display resultset i was wondering if there is a way to display the results in JLabels or is that process the same for both jtables and jlabels?
- 04-22-2011, 04:43 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 23
- Rep Power
- 0
yes there is .... you have to :
- store the JDBC variables into another variable
for example :
Statement sqlCommand = conn.createStatement();
Statement sqlCommand2 = conn.createStatement();
ResultSet res ;
ResultSet res2;
res = sqlCommand.executeQuery("SELECT * FROM Person WHERE personID = 1")
res2 = sqlCommand2.executeQuery("SELECT * FROM Person WHERE personID = 2")
while (res.next()) {
firstname1 = res.getString("firstname");
lastname1 = res.getString("lastname");
}
while (res2.next()) {
firstname2 = res2.getString("firstname");
lastname2 = res2.getString("lastname");
}
So now you have stored all the variables you got from the database in java variables...Next step is making getter methods for the java variables:
public String getFirstName1(){
return firstname1;
}
public String getLastName1(){
return lastname1;
}
public String getFirstName2(){
return firstname2;
}
public String getLastName2(){
return lastname2;
}
And the final step...you use the variables on the JLabels...for example
private static JLabel label1, label2;
label1 = new JLabel();
label1.setText(getFirstName1() + " " + getLastName1() );
label2 = new JLabel();
label2.setText(getLastName2() + " " + getLastName2() );
But be careful ..JLabel's only work with Strings
I Hope this helps !Last edited by ady_bavarezu89; 04-22-2011 at 04:50 PM.
- 04-22-2011, 05:03 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
JDBC MySql question
By santa in forum New To JavaReplies: 12Last Post: 01-18-2011, 03:47 PM -
A question on JDBC&SQL Server
By an24 in forum JDBCReplies: 5Last Post: 01-18-2010, 11:23 AM -
JDBC statement question
By nick2price in forum Advanced JavaReplies: 21Last Post: 09-29-2008, 02:09 PM -
jdbc/ swing code problem
By sami in forum Advanced JavaReplies: 1Last Post: 08-13-2007, 02:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks