Hi ,
I'm connecting to db2 using a JDBC driver and then running the piece of code below :
while (rs.next()) {
String a1 = rs.getString(1);
String a2 = rs.getString(2);
String a3 = rs.getString(3);
String a4 = rs.getString(4);
String a5 = rs.getString(5);
System.out.printf(" %s %s %s %s %s\n", a1, a2, a3, a4, a5);
System.out.print("");
}
Then I get the below output:
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
Now I wonder what do I need to do to display/insert the above output into a Jtable. My intention is to create a a small monitor tool uisng GUI's and then basically in the GUI the window should look like:
DBNAME AGENT_ID AUTHID APPL_NAME APPL_STATUS
---------------------------------------------------------
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
T01KATD1 58105 TKUGOM1 db2jcc_application UOWWAIT
Please any ideas will be highly appreciated. Thanks.
creating a Jtable using swing
Started by hariza, Aug 19 2010 04:02 AM
1 reply to this topic
#1
Posted 19 August 2010 - 04:02 AM
|
|
|
#2
Posted 20 August 2010 - 04:25 AM
If you store all of the table data in a two-dimentional vector, and then write another vector and manually insert the column names into it, you should be able to just create a JTable with the constructor:
...of course, the data you're getting just comes as one big string. You'll probably need another method to break the text up (it seems to me that the data are seperated by a space... You could easily write a method that breaks the whole string up into smaller strings whenever is finds a space, and then call the method with the string as an argument, which returns the smaller strings as a vector object). Then, once this is broken up and the two-dimensional vecotr is populated, write another vector to manually contain the column names for your table, call the constructor mentioned above, and I think that should work.
Also, I suggested using a vector because you didn't make any mention of how much data there will be. If all of your outputs are going to be like your example, with 5 (or however many) strings returned every time, you're probably better off using an array. If the number of data items can change, I'd advise using a vector.
Remember, i'm not a very good Java programmer, but still I hope this helps! ^_^
~Fae
JTable(Vector rowData, Vector columnNames)
...of course, the data you're getting just comes as one big string. You'll probably need another method to break the text up (it seems to me that the data are seperated by a space... You could easily write a method that breaks the whole string up into smaller strings whenever is finds a space, and then call the method with the string as an argument, which returns the smaller strings as a vector object). Then, once this is broken up and the two-dimensional vecotr is populated, write another vector to manually contain the column names for your table, call the constructor mentioned above, and I think that should work.
Also, I suggested using a vector because you didn't make any mention of how much data there will be. If all of your outputs are going to be like your example, with 5 (or however many) strings returned every time, you're probably better off using an array. If the number of data items can change, I'd advise using a vector.
Remember, i'm not a very good Java programmer, but still I hope this helps! ^_^
~Fae
I'll ask a lot of questions (most of them probably stupid stuff). Bear with me, i'm still learning! ^_^ Also, I'll try to answer as many questions as I can as well, but I'm not very good yet. I'm sure I'll be of more use once I get better :)


Sign In
Create Account

Back to top









