jdbc: Get the SQL Type Name from java.sql.Type code

Java 8 and later: JDBCType & SQLType

With improvements in the API’s, as of Java 8 and JDBC 4.2, we have JDBCType and SQLType, and in the same spirit as some of the other examples can be simply used as follows:

String typeName = JDBCType.valueOf(-5).getName();

But of course, why using the numeric types to begin with. Make a habit, and switch over from numeric’s to the enum constants defined in JDBCType:

String typeName = JDBCType.BIGINT.getName();

et voilĂ !

However, that might not be enough to have something good enough for using in a DDL … you might need to implement vendor specific translation. As an example, you might need to consider to translate VARCHAR to VARCHAR2 in the case of Oracle.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)