resultSetMetaData.getxxx -Oracle getting jdbc table properties 
Author Message
 resultSetMetaData.getxxx -Oracle getting jdbc table properties

Started playing around with the resultSetMetaData.getxxx group of methods
in the java.sql Interface ResultSetMetaData,

I'm using the method getTableProps to extract the data from my oracle
database. (ver 8.0)

got these interesting results, and compared them with desc tablename in
oracle.

 Name                            Null?    Type                  jdbc
                                                                getColumn
                                                                type
 ------------------------------- -------- ----
 REPORTID                        NOT NULL VARCHAR2(10)          12
 LINENO                          NOT NULL NUMBER(3)             2
 RLDATE                                   DATE                  93
 START_TIME                               DATE                  93
 END_TIME                                 DATE                  93
 HOURS                                    NUMBER(3,1)           2
 TASK                                     VARCHAR2(100)         12
 PAYMENTNO                                NUMBER(6)             2

ie a table in oracle of type Varchar2, is seen by jdbc as column type 12,
     table in oracle of type Date,     is seen by jdbc as column type 93,
etc.

I'm curious to find out if there is a table somewhere that correlates the
int returned by the method getColumnType with datatypes, had a look at the
Java class help files but nothing obvious there, any ideas????


my code below for interest ....

public void getTableProps (PrintWriter out, String tableName) {
/*

*/
        Properties info = new Properties();
          info.put("user","username");
          info.put("password","password");
                out.println("getting getTableProps for table
:"+tableName+"<P>");
                String temp = "";
                String l_query ="";
                try {
                                                Connection m_connection =
DriverManager.getConnection(
               "connect string",info);
                                                out.println("Connected in
getTableProps<P>");

                                                Statement stmt =
m_connection.createStatement();
                                                ResultSet rs =
stmt.executeQuery("select * from "+tableName);
            ResultSetMetaData resultSetMetaData = rs.getMetaData();
            int numColumns = resultSetMetaData.getColumnCount();
                                                out.println("Number of
columns in table "+tableName+" = "+numColumns+"<BR>");
            StringBuffer strBuf = new StringBuffer();

out.println("<center><table BORDER COLS=6 WIDTH='100%' >");

strBuf.append("<tr><td>getColumnLabel</td><td>getColumnType</td><td>getPrecision</td>");

strBuf.append("<td>getScale</td><td>getSchemaName</td><td>getTableName</td></tr>");
                                    out.println(strBuf);
            //strBuf = new StringBuffer();
            for(int i = 1; i <= numColumns; i++)
             {

out.println("<tr><TD>"+resultSetMetaData.getColumnLabel(i)+"</TD>");

out.println("<TD>"+resultSetMetaData.getColumnType(i)+"</TD>");

out.println("<TD>"+resultSetMetaData.getPrecision(i)+"</TD>");
              out.println("<TD>"+resultSetMetaData.getScale(i)+"</TD>");

out.println("<TD>y:"+resultSetMetaData.getSchemaName(i)+"</TD>");

out.println("<TD>z:"+resultSetMetaData.getTableName(i)+"</TD>");
                                      out.println("</tr>");
                                      //out.println(strBuf);//send table
to client
             }

out.println("</center></table>");
                                } catch (Exception ex) {out.println("Error
in insertRecords<P>"+
                                                ex.toString()+"<BR>"+
System.getProperties()+"<BR>");}
        }// end updateRecords

Quote:
}



Sat, 14 Sep 2002 03:00:00 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Getting table names with ResultSetMetaData

2. Oracle JDBC Driver bug with ResultSetMetaData

3. Urgent: system is getting hanged while getting metadata from oracle using jdbc

4. Oracle JDBC Thin Applet + MS IE: SecurityException accessing jdbc.drivers system property

5. Oracle JDBC Thin Applet + MS IE: SecurityException accessing jdbc.drivers system property

6. Unable to execute JDBC method getCatalogName of class ResultSetMetaData

7. JDBC ResultSet and ResultSetMetaData

8. ResultSetMetaData problems with JDBC:ODBC

9. JDBC and ResultSetMetaData

10. Unable to execute JDBC method getCatalogName of class ResultSetMetaData

11. Getting rid of the IDENTITY property on a column withou getting rid of the column

12. Getting Table Name from Field Properties


 
Powered by phpBB® Forum Software