Java DatabaseMetaData .getTypeInfo ()

Syntax

DatabaseMetaData.getTypeInfo() has the following syntax.

ResultSet getTypeInfo()   throws SQLException

Example

In the following code shows how to use DatabaseMetaData.getTypeInfo() method.


import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
//from  w  w  w.  j  a  va 2s  . c o m
public class Main {

  public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();

    DatabaseMetaData dbmd = conn.getMetaData();      

    ResultSet rs = dbmd.getTypeInfo();
    while (rs.next()) {
        String typeName = rs.getString("TYPE_NAME");
        short dataType = rs.getShort("DATA_TYPE");
        String createParams = rs.getString("CREATE_PARAMS");
        int nullable = rs.getInt("NULLABLE");
        boolean caseSensitive = rs.getBoolean("CASE_SENSITIVE");
        System.out.println("DBMS type " + typeName + ":");
        System.out.println("     java.sql.Types:  "  + dataType);
        System.out.print("     parameters used to create: ");
        System.out.println(createParams);
        System.out.println("     nullable?:  "  + nullable);
        System.out.print("     case sensitive?:  ");
        System.out.println(caseSensitive);
        System.out.println("");

    }
    conn.close();
  }

  private static Connection getHSQLConnection() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    String url = "jdbc:hsqldb:data/tutorial";
    return DriverManager.getConnection(url, "sa", "");
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.sql »




DatabaseMetaData
ParameterMetaData
PreparedStatement
ResultSet
Timestamp