Storing Result set into an array

Posted by OVERTONE on Stack Overflow See other posts from Stack Overflow or by OVERTONE
Published on 2010-04-23T15:48:34Z Indexed on 2010/04/23 15:53 UTC
Read the original article Hit count: 177

Filed under:
|
|
|

i know this should be simpel and im probably staring straight at the problem but once again im stuck and need the help of the code gurus.

im trying too take one row from a column in jdbc, and put them in an array.

i do this as follows:

public void fillContactList()
       {
           createConnection();
           try
           {
               Statement stmt = conn.createStatement();
               ResultSet namesList = stmt.executeQuery("SELECT name FROM Users");
               try
               {
                   while (namesList.next())
                   {
                       contactListNames[1] = namesList.getString(1);
                       System.out.println("" + contactListNames[1]);
                   }   
               }
               catch(SQLException q)
               {

               }
               conn.commit();
               stmt.close();
               conn.close();
           }
           catch(SQLException e)
           {

           }

creatConnection is an already defined method that does what it obviously does. i creat my result set while theres another one, i store the string of that column into an array. then print it out for good measure. too make sure its there.

the problem is that its storing the entire column into contactListNames[1]

i wanted to make it store column1 row 1 into [1]

then column 1 row 2 into [2]

i know i could do this with a loop. but i dont know too take only one row at a time from a single column. any ideas?

p.s ive read the api, i jsut cant see anything that fits.

© Stack Overflow or respective owner

Related posts about sql

Related posts about jdbc