![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e290. Listing Available SQL Types Used by a DatabaseThis example retrieves the SQL data types supported by a database and driver.try { // Get database meta data DatabaseMetaData dbmd = connection.getMetaData(); // Get type info ResultSet resultSet = dbmd.getTypeInfo(); // Retrieve type info from the result set while (resultSet.next()) { // Get the database-specific type name String typeName = resultSet.getString("TYPE_NAME"); // Get the java.sql.Types type to which this database-specific type is mapped short dataType = resultSet.getShort("DATA_TYPE"); // Get the name of the java.sql.Types value. // This method is implemented in e291 Getting the Name of a JDBC Type String jdbcTypeName = getJdbcTypeName(dataType); } } catch (SQLException e) { }Here's an example of output for the MySQL database: MySQL Type Name, JDBC Type Name TINYINT, TINYINT BIGINT, BIGINT MEDIUMBLOB, LONGVARBINARY MEDIUMTEXT, LONGVARBINARY LONGBLOB, LONGVARBINARY LONGTEXT, LONGVARBINARY BLOB, LONGVARBINARY TEXT, LONGVARBINARY TINYBLOB, VARBINARY TINYTEXT, VARBINARY CHAR, CHAR NUMERIC, NUMERIC DECIMAL, DECIMAL INT, INTEGER MEDIUMINT, INTEGER SMALLINT, SMALLINT FLOAT, FLOAT DOUBLE, DOUBLE DOUBLE PRECISION, DOUBLE REAL, DOUBLE VARCHAR, VARCHAR ENUM, VARCHAR SET, VARCHAR DATE, DATE TIME, TIME DATETIME, TIMESTAMP TIMESTAMP, TIMESTAMP
e285. Listing the String Functions Supported by a Database e286. Listing the Numeric Functions Supported by a Database e287. Listing the System Functions Supported by a Database e288. Listing the Time and Date Functions Supported by a Database e289. Getting the Maximum Table Name Length in a Database e291. Getting the Name of a JDBC Type © 2002 Addison-Wesley. |