简体   繁体   中英

How to get database specific datatypes in java?

Consider this code segment

Class.forName ("oracle.jdbc.OracleDriver");

          connection = DriverManager.getConnection
             ("jdbc:oracle:thin:@//XXX.XXX.XXX.XXX:1521/xe", "abc", "def");
 DatabaseMetaData metaData=connection.getMetaData();
        ResultSet rsc= metaData.getColumns(null, "MYSCHEMA", "MYTABLE", null);
        while (rsc.next()){

            System.out.println(rsc.getString("COLUMN_NAME").toUpperCase());
            System.out.println(rsc.getString("TYPE_NAME").toUpperCase());
            System.out.println(rsc.getInt("COLUMN_SIZE"));
            System.out.println(rsc.getInt("DECIMAL_DIGITS"));   
            System.out.println(rsc.getString("IS_NULLABLE").toUpperCase()) ;
            System.out.println(rsc.getInt("ORDINAL_POSITION"));
            System.out.println(rsc.getInt("DATA_TYPE"));
            System.out.println("********************************************");
        }

With this code segment I can get to know that if suppose MYTABLE has a column whose name is MYTABLEID of type NUMBER in Oracle then how can I get to know that what will be the corresponding datatype name of NUMBER equivalent in Mysql or PostGresql ? Basically aim is to get database specific datatype. Like in Oracle we have CLOB datatype but in postgresql we have bytea as an equivalent datatype. I wanted database specific type so that I can create DDL (Create table statement) to create table in a particular database(from oracle to mysql or postgresql etc).

I would create an XML file with info on each database and any specific database datatype (eg CLOB, or bytea), then I would use this info and retrieve it for any specific use you may have in your code. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM