Hello, I have the following problem but first the situation : I have succesfully connected to an existing Ms-Access database and retrieved the resultset of three colomns. One colomn of the resultset is "name" which I'd like to place in a Jlist. To the right of my Jlist are some Jtextfields which are the other fields of my database and are also in my resultset (the other columns). Here's what I want, when I click on a name in the Jlist I want the Jtextfields to change also with their corresponding values... Here's the code of what I already have. Somebody already gave me some help and told me to use Vectors. But it's not really working.
try{ // create a statement handler Statement sqlStatement = databaseConnection.createStatement();
// create a sql-string String sql = "SELECT NAME,TYPE,LENGTH,DESCRIPT FROM VELD ORDER BY NAME"; ResultSet results = sqlStatement.executeQuery(sql); ResultSetMetaData rsmd = results.getMetaData(); int totCol = rsmd.getColumnCount();
// here are the two vectors one for the columns one for the rows but how do I USE THEM ??? while (results.next()) { Vector newCol = new Vector(); for (int i =1 ; i <= totCol; i++ ) { newCol.addElement(results.getObject(i)); rows.addElement(newCol); } }
// close connection databaseConnection.close(); System.out.println("the connection is closed !");
} catch (SQLException sqle) { System.err.println(sqle); } } Can anybody help me ?? Thanks Kristof
Paul Stevens
Ranch Hand
Joined: May 17, 2001
Posts: 2823
posted
0
You could create some class to hold each row of the resulset. Put in a toString() which returns the Name. Put all of those in a Vector and create your JList. When something is selected, cast the Object selected to your class and use the setText() of the JTextfields to fill with the other values in your class.
suheel hussain
Greenhorn
Joined: Nov 01, 2001
Posts: 16
posted
0
I had a simialr problem where selecting an entry in JList brings up an internal frame, etc. My solution was to create a hash table and use JList entry as a key for corresponding string to be displayed in text field. Thus, selected JList entry is used to search corresponding text field in hash table. (I prefer using Hashtable instead of Vector.)
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.