13 Replies Latest reply on Sep 12, 2007 6:19 AM by 807600

    help to get the column names from ResultSet.


      I hava a ResultSet and i want the column names into a String Array.
      i wrote the code to get the column names as below,

      String s = "select Dept_No,Dept_Name from tb_dept";
      rs = statement.executeQuery(s); // ResultSet defined before
      String[] columnNames1 = null;
      ResultSetMetaData meta = rs.getMetaData ( ) ;
      for (int x = 1; x <= meta.getColumnCount(); x++)
      columnNames1[x] = meta.getColumnName(x).toString();

      but i'm getting NullPointer exception. However if i print the column names means its printing the first column name and giving NullPointer Exception at the next step.

      Can anyone help me...