3 Replies Latest reply: Apr 3, 2006 7:55 AM by Avi Abrami RSS

    DESC <tablename> : invalid SQL statement

    495311
      I am trying to use the command " desc <tablename>" through jdbc. But everytime it throws up invalid sql statement exception. The desc command when executed through sqlplus gives the desired output. Its a Oracle 10g xe release.

      Thanks,

      Ameya
        • 1. Re: DESC <tablename> : invalid SQL statement
          Avi Abrami
          Ameya,
          DESC[RIBE] is a SQL*Plus command, not a SQL statement. The DESC command queries the Oracle data dictionary, something like:
          select COLUMN_NAME, DATA_TYPE
            from USER_TAB_COLUMNS
           where TABLE _NAME = 'YOUR_TABLE'
          However, in JDBC you could probably use the ResultSetMetaData interface to obtan the same information.

          Good Luck,
          Avi.
          • 2. Re: DESC <tablename> : invalid SQL statement
            dvohra21
            Obtain database meta data.
            Class.forName("oracle.jdbc.OracleDriver");
              String url="jdbc:oracle:thin:@localhost:1521:orcl";
              Connection currentConnection = DriverManager.getConnection(url,
                                 "OE", "");
              
             DatabaseMetaData metadata = currentConnection.getMetaData(); 
              String[] names = {"TABLE"}; 
              ResultSet tables = metadata.getTables(null,"%", "%", names); 
              while (tables.next()) { 
            
              String tableName = tables.getString("TABLE_NAME"); 
              String tableSchema = tables.getString("TABLE_SCHEM"); 
              String tableType = tables.getString("TABLE_TYPE"); 
            
              
            
               ResultSet columns = metadata.getColumns(null, "%", tableName, "%");
            while (columns.next()) { 
              String columnName = columns.getString("COLUMN_NAME"); 
              String datatype = columns.getString("TYPE_NAME"); 
              int datasize = columns.getInt("COLUMN_SIZE"); 
              int nullable = columns.getInt("NULLABLE"); 
            
            }
            }
            • 3. Re: DESC <tablename> : invalid SQL statement
              Avi Abrami
              Deepak,
              I believe the Oracle documentation recommends that the use of javax.sql.DataSource is preferred over that of java.sql.DriverManager.

              Good Luck,
              Avi.