2

I am creating the following table in oracle:

CREATE TABLE TEST
(
 DKEY INTEGER NOT NULL PRIMARY KEY,
 NOM VARCHAR2(255) NOT NULL
)

When i try to get the type of the DKEY field using this java code, I get the following result:

DatabaseMetaData md = cnx.getMetaData();
ResultSet rsmd = md.getColumns(null, strSchema, strTableName, "%");
while (rsmd != null && rsmd.next()) {
    String strTmp = rsmd.getString("SQL_DATA_TYPE");  // this return 0 for field DKEY
    int intDType = rsmd.getInt("DATA_TYPE");          // this return 3 for field DKEY
    String strFType = rsmd.getString("TYPE_NAME")     // this return NUMBER for field DKEY
}

Why do i get NUMBER instead of INTEGER?

1
  • Did you read the chapter in the Oracle manual that describes the available datatypes? Because that does answer your question. Commented May 30, 2013 at 14:52

2 Answers 2

5

Although you can specify INTEGER as the data type in the SQL statement, Oracle will use NUMBER(38) in its implementation.

See Oracle data types here and this article.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer, one more question : why rsmd.getString("COLUMN_SIZE") returns 0 not 38? is there another methode to get the size? i tried getPrecision but also it returned 0
If you read the javadoc for getPrecision, docs.oracle.com/javase/6/docs/api/java/sql/…, it says 0 is returned for data types where the column size is not applicable. I don't know any other way. Use SQL to get table metadata with a DESCRIBE statement or whatever Oracle uses.
getPrecision is going to return 0 if you specify Integer, Number, or Number(*,n) where n is >= 0. sqlfiddle.com/#!4/be559/2
0

I think the table column DKEY property type is NUMBER

But try

while (rsmd != null && rsmd.next()) {
    String strTmp = rsmd.getString("SQL_DATA_TYPE");  // this return 0 for field DKEY
    int intDType = Integer.parseInt(rsmd.getLong("DATA_TYPE"));          // this return 3 for field DKEY
    String strFType = rsmd.getString("TYPE_NAME")     // this return NUMBER for field DKEY
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.