DatabaseMetaData.getColumns

Hello,
Can anyone explain which unit used for 'COLUMN_SIZE'? Bytes? Bits? I need to retreive database structure and I prefer to use JDBC but I think it isn't possible.
For instance in Oracle: Float(n) n -> number of bits. In PostgreSQL float4 4 -> number of bytes. :(
If I couldn't get the COLUMN_SIZE unit then DatabaseMetaData is 80% useless. I couldn't get anything except tables names and column names. :(
With regards,
Pavel Krupets

ResultSetMetaData.getColumnDisplaySize(int) gives you the corresponding column size

Similar Messages

  • DatabaseMetaData.getColumns(...) returns an invalid size of NVARCHAR2

    Hi,
    I have the following problem.
    I'm using ojdbc14.jar version 10.2.0.2.0
    I'm trying to read table metadata from database using DatabaseMetaData.getColumns(...). And, when I read the size of a NVARCHAR2 column (using either COLUMN_SIZE or CHAR_OCTET_LENGTH) it returns the double of the maximum length (as if it were expressed in bytes!)
    Javadocs says: COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
    Does anyone have the same problem?
    Does anyone know if there is an open bug on this topic?
    I will really appreciate your help
    Thanks
    ArielUBA

    Hi Ashok,
    Thanks for your answer.
    I tried changing NLS_LENGTH_SEMANTICS parameter, and unfortunately it was unsuccessful :-(
    I'm using NVARCHAR2 column type and in http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams127.htm says the following:
    NCHAR, NVARCHAR2, CLOB, and NCLOB columns are always character-based
    I also tried to use (in a simple test case) the newest available driver 11.1.0.6.0. (but, for production I need ojdbc14.jar) and I got the same result.
    PreparedStatement smt = connection.prepareStatement("ALTER SESSION SET NLS_LENGTH_SEMANTICS=CHAR");
    smt.execute();
    connection.commit();
    DatabaseMetaData metaData = connection.getMetaData();
    ResultSet columns = metaData.getColumns(null, "ENG_AAM_572_STD_1E", "PPROCINSTANCE", "V_LOAN_NUMBER");
    dispVerticalResultSet(columns);The column length of V_LOAN_NUMBER is 31 characters and the result was:
    TABLE_CAT=null
    TABLE_SCHEM=ENG_AAM_572_STD_1E
    TABLE_NAME=PPROCINSTANCE
    COLUMN_NAME=V_LOAN_NUMBER
    DATA_TYPE=1111
    TYPE_NAME=NVARCHAR2
    COLUMN_SIZE=62
    BUFFER_LENGTH=0
    DECIMAL_DIGITS=null
    NUM_PREC_RADIX=10
    NULLABLE=1
    REMARKS=null
    COLUMN_DEF=NULL
    SQL_DATA_TYPE=0
    SQL_DATETIME_SUB=0
    CHAR_OCTET_LENGTH=62
    ORDINAL_POSITION=32
    IS_NULLABLE=YES
    Are you sure that I'm dealing with the bug 4485954?
    Do you know if there is a workaround?
    Thanks in advance for your time
    ArielUBA

  • Java.sql.DatabaseMetaData.getColumns field REMARKS is empty

    I'm trying to get table and columns comments using java.sql.DatabaseMetaData.getColumns and REMARKS field from the rs . But it's empty alought there are comments defined in oracle.
    In using oracle 10.2 (XE) , with jdevloper (10.1.3) and jdbc 1.4 (drivers that come with the installation).
    Any ideas will be welcome

    Amihay,
    Your question has been discussed several times previously in this forum. Did you search the forum archives? Basically the answer to your question can be found in the Oracle JDBC Developer's Guide and Reference (which is part of the Oracle documentation and can be accessed via the OTN Web site). Refer to the section entitled Supported Connection Properties. You need to set the property "remarksReporting" to "true". The documentation also has sample code demonstrating how to set the property.
    Good Luck,
    Avi.

  • DatabaseMetaData.getColumns().next() goes on forever

    Hi,
    I am using the following code to get all the column names using DatabaseMetaData.getColumns().next()
    The loop never stops. I am using Java 1.4 and downloaded the Oracle 9i's (9.2.0.8) ojdbc.jar from
    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html
    My table "GA_TABLE" has only 22 columns. But this loop keeps on showing the same column names again and again.
    The next() never stops.
    I am running the Java program from Eclipse 3.2
    Could you please help me?
    I greatly appreciate your help.
    Thank you.
    listColumnNames(String tableName) {
    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
    connOracle = DriverManager.getConnection(strConnectURL, props);
    DatabaseMetaData dbmeta = connOracle.getMetaData();
    ResultSet dbColumns = dbmeta.getColumns(null, null, tableName,null);
    for (int i =0; dbColumns.next(); i++){
    log.info(dbColumns.getString("COLUMN_NAME"));
    }

    I don't know about it... If there is a fix, it will be in the latest driver
    available on the Oracle download page now, so that's the version of ojdbc14.jar
    that you should try.
    Also, please make a new table, just to test this bug. It can have the same
    DDL as your original table, but name it something unique to the DBMS such as:
    CREATE TABLE EVERYONELOVESJOE(....)
    then run your little metadata query on that table, and tell us if the loop
    never ends... In your original test, just how high does i get before you quit?
    thanks,
    Joe

  • DatabaseMetaData.getColumns COLUMN_DEF

    I want the description of table columns using DatabaseMetaData.getColumns().
    When I loop thru the ResultSet I got an exception each time I try to read the column's default value.
    Debug traces look like this :
    DRVR OPER OracleResultSetImpl.getString(columnIndex=13)
    DRVR WARN DBError.findMessage(errNum, obj): returned Stream wurde schon geschlossen
    java.sql.SQLException: Stream wurde schon geschlossen
    Everything else is just fine

    I don't know about it... If there is a fix, it will be in the latest driver
    available on the Oracle download page now, so that's the version of ojdbc14.jar
    that you should try.
    Also, please make a new table, just to test this bug. It can have the same
    DDL as your original table, but name it something unique to the DBMS such as:
    CREATE TABLE EVERYONELOVESJOE(....)
    then run your little metadata query on that table, and tell us if the loop
    never ends... In your original test, just how high does i get before you quit?
    thanks,
    Joe

  • DatabaseMetaData getColumns :- type_name returns 'int identity' (SQLServer)

    Hi all,
    I am using the JDBC DatabaseMetaData API, getColumns() method. The back end is SQLServer 2005.
    Now according to how the API is specified, I am using index 6(I think)(type_name) to retrieve the data type name from the resultset for each column.
    However, for one column I am getting the datatype as "int identity".
    This column has been set as identity with increment 1 in SQLServer 2005. But when I say type_name, why am I getting this "identity" word?? Should'nt I just be getting "int"??
    I have found this problem to be unique to SQLServer... unless of course if someone has found this same behaviour on some other DB vendor.
    Does anyone have any reason as to why, for SQLServer, this type_name index returns the "<datatype> + 'identity' "?
    Actually, in my project, I just need the actualy data type only!! I do not need the identity keyword at all! (So I had to create a work around where it would ignore thhis word and just take the data type.... :-( )
    Thanx.

    [Check this|http://media.datadirect.com/download/docs/connectsqlxml/jdbcug/jdbcsqls.htm] and search for "data types".
    (This info should also be found in the docs for the Driver.)
    Every DB defines its own types, of course. Usually at least partially compliant with SQL 92/98. It is up to the driver to map those types to the JDBC types.
    You can also see this.
    There is, under Connection, a getTypeMap method. Unfortunately, if the app doesn't add any types to the map, this method returns an empty map. I haven't palyed with this, but it is definately possible that using it will only return user-defined types (mapped by the application). Then again, it may return the full Map as soon as one is added, then again, the Driver, may add the type conversions to the map itself, on initialisation, and so, it may return the complete map from from the beginning. I don't know. As I said, I haven't played with it.

  • Getting AUTO_INCREMENT info from DatabaseMetaData

    Hi all,
    I am experimenting with DatabaseMetaData on a MySQL database. Does anyone know how to get the information that a column of a table is autoincremented.
    The DatabaseMetaData.getColumns(...) method does not seem to return this info.
    Suppose a table created by
    CREATE TABLE book
    (book_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255))
    The DatabaseMetaData returns all information of this table except that book_id is AUTO_INCREMENT.
    Or am I missing something?
    cu
    Achim

    You can use what the DatabaseMetaData.getColumns(...) return. Because the method DatabaseMetaData.getColumns(...) return a ResultSet object.
    From the ResultSet you can know if the colunm is autoincrement or not.
    Use the ResultSet.getMetaData() method that return a ResultSetMetaData object, then use the ResultSetMetaData.isAutoIncrement(int column) method that Indicates whether the column is automatically numbered.Good luck

  • GetColumns returns nothing

    Hi,
    I have two cases:
    1. databasemetaData.getColumns("", "SCOTT", "TableOne",null); returns me resultset which has info about all the columns in table 'TableOne'.
    BUT
    2. databasemetaData.getColumns("", "SCOTT", "SynonymOne",null); returns me nothing. Here SynonymOne is a valid synonym on my database.
    Can you please tell me how do I get info about columns by passing a synonym name? This is very urgent and any help regarding this is highly appreciated.
    Thanks,
    Yousuf Baig

    I wish I could help you but I know little of table synonyms. The only thing close that I know of is the long table names in DB2/400 vs. the 10 character restricted system names. Could it be a driver shortcoming? What DB driver and database are you using? MAybe there's a better approach to your overall problem besides sysnonyms?
    Cliff

  • DatabaseMetaData

    I am not to sure how to use this class...Say my table name is assets and my database name is auto - how do I get the column names???
    Can u show me some code...
    Should it b like:
    ResultSet r = DatabaseMetaData.getColumns("","","assets","");
    while (r.next()) {
    System.out.print(r.getString(4));
    I have looked at the api but I am still a bit lost.
    Can u show where I have gone wrong??
    any input will b appreciated
    Ushanta

    Quoted from the API docs: "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
    Thus you should use ResultSet r = DatabaseMetaData.getColumns(null,null,"assets",null);

  • DatabaseMetaData.getIndexInfo()

    Hi,
    I am trying to read the schema from 9i server using DatabaseMetaData. When the method getIndexInfo is been used, it returns Type "tableIndexStatistic". How can i get the particular column name when the type is tableIndexStatistic ?.
    Biju.

    I have the same problem when using DatabaseMetaData.getColumns.
    When I call that method on several tables I get "java.sql.SQLException: ORA-01031: insufficient privileges" and eventually "java.sql.SQLException: ORA-01000: maximum open cursors exceeded".
    How can I know in advanced using JDBC for which tables I can get the metadata?
    Thanks.

  • Error while generating DDL commands using startSQLRepository for a new Repository

    Hi,
    I am trying to generate DDL Commands using startSQLRepository for my new repository SubashRepository so that I can use them to create new table structure.
    All the repository related changes looks good. i can see my repository in ACC
    When I run the command:
    startSQLRepository -m SupremeATG –repository /com/supreme/SubashRepository /com/supreme/subashRepository.xml -outputSQLFile C:/ATG/ATG9.3/SupremeATG/config/com/supreme/subashRepositoryDDL.txt
    I get following error:
    Table 'SUBASH_MEMBER' in item-descriptor: 'member' does not exist in a table space accessible by the data source.  DatabaseMetaData.getColumns returns no columns
    Note:
    * errors related to definition file were cleared as the same command threw relevant exception while trying to store a array property with out creating a multi table.
    * Now this is the only exception i see
    * Some DDL are getting generated in the output file, but those are related to inventory repository (I am not sure why this is happening as I have specifically gave the path to my definition file).
    Any help in resolving this is highly appreciated.

    Pl post in the ATG forum

  • What is table schema name?

    Hi,
    I was looking at DatabaseMetaData::getColumns() while searching for a way to get a table's column names and I run into these ugly params catalog and schemaPattern. Of course nowhere on the sun's site could I find a definition of these terms although they're used quite often in the API documentation. So I turned to a specific DBMS provider and found out that catalog is a fancy term for the system metadata. But what about the String schema param? I usually see a table's schema referred to as the "structure" of the table, what columns it contains of which types. But I've never known this "schema" can have a string name. Anyone so kind to explain it to me or better point me to a text that has definitions and explanations of the concepts used in the JDBC API documentation? And more generally for JDK where do you folks usually go when you want a simple explanation of how things work, not the dry listing of function and parameter names? Look at MSDN for example, it is both a good reference and a reasonable self-contained tutorial. Not that I praise Microsoft but...
    BTW I found that probably ResultSetMetaData is more suitable for my initial purposes, but still the questions bother me. So if you have any suggestion please let me know.
    Thank you in advance

    To answer your question, what is a table schema name?, it is the name of the schema that the table belongs to. If you have an Oracle database, MYDB, it will have at the very least two users which are SYS and SYSTEM, these are schema names, there are objects that exists in their schema. If you create a new user, JAKE, and then create a bunch of objects as JAKE, these objects are said to belong to the JAKE schema. All objects are like this, not just tables (indexes, sequence tables, triggers, etc.).

  • Java.sql.types and oracletypes

    There appear to be difference in the way the constants are mapped in java.sql.types vs oracletypes(). For example date is '91' in oracletypes and '93' in java.sql.types. The DatabaseMetaData.getColumns() function reports data_type as a java.sql.type. Is there any mapping available from one to the other.
    Thanks

    Erm,
    One way to find out, I reckon.
    Good Luck,
    Avi.

  • Bug in latest 11g JDBC driver

    We have found a problem when using the latest 11g JDBC driver ("11.1.0.7.0-Production") and connecting to a 10g database. If the includeSynonyms=true property is set when opening the connection, then calling DatabaseMetaData.getColumns() will not return any columns for views. Tables and synonyms work, but not views. Without the includeSynonyms property, columns are returned correctly for tables and views, but obviously not for synonyms.
    The previous 11g driver ("11.1.0.6.0-Production+") did not have this problem.
    Our testing was done using ojdbc5.jar with Java 1.5, and a 10.2.0.1.0 database. I have not tested if the same problem exists when connecting to a 11g database, or when using ojdbc6.jar/Java 1.6.
    Is this a known issue? Is there a workaround other than reverting to the older driver?
    Thanks.
    Steve

    Are you sure that DatabaseMetaData#getColumns is actually working? AFAIK, this is not implemented feature in Oracle JDBC driver.

  • GetTypeInfo

    We are doing some work around database independence, and as part of this we use meta-data via JDBC to support this.
    Initially however, as part of our investigation to see what types are supported in Oracle, we used the java.sql.DatabaseMetaData.getTypeInfo method. We checked the information returned from this.
    No entry was returned for JDBC type 3, i.e. java.sql.Types.DECIMAL (we can tell this since Column 2 of the resultset gives the numeric JDBC type).
    However when we analyse some existing database tables using the java.sql.DatabaseMetaData.getColumns() method, we find that some columns are of type 3, i.e. DECIMAL.
    Is there a bug in the getTypeInfo method ? Is the DECIMAL type supported?
    We are using the 8.1.6 driver.

    The database supports the type DECIMAL as a synonym for the local type NUMBER(38).
    This would have the same behavior as the type reported for BIGINT (code -5).
    I do not know whether DECIMAL is not reported because it would be outside of the JDBC spec for typecode 3, or if this is simply an oversight. I'd rather defer to our JDBC developers on this.

Maybe you are looking for