13 Replies Latest reply: Sep 12, 2007 1:19 AM by 807600 RSS

    help to get the column names from ResultSet.

    807600
      Hi,

      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...

      Thanks,
      Rashmy