Example usage for java.sql DatabaseMetaData getTypeInfo

List of usage examples for java.sql DatabaseMetaData getTypeInfo

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getTypeInfo.

Prototype

ResultSet getTypeInfo() throws SQLException;

Source Link

Document

Retrieves a description of all the data types supported by this database.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    ResultSet resultSet = null;//from   w  w w.j av  a2  s. c  o  m
    Class.forName(DRIVER);
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

    DatabaseMetaData metadata = connection.getMetaData();
    resultSet = metadata.getTypeInfo();
    while (resultSet.next()) {
        String typeName = resultSet.getString("TYPE_NAME");
        System.out.println("Type Name = " + typeName);
    }
    resultSet.close();
    connection.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);//w w  w. j av a2s  .  c o  m

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    DatabaseMetaData dbmd = connection.getMetaData();
    ResultSet resultSet = dbmd.getTypeInfo();

    while (resultSet.next()) {
        String typeName = resultSet.getString("TYPE_NAME");

        short dataType = resultSet.getShort("DATA_TYPE");
    }
}

From source file:Main.java

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("");

    }/*ww  w .j a  v a2  s  . c o m*/
    conn.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);//from  w w w .  j a  v  a  2  s.c  o m

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    DatabaseMetaData dbmd = connection.getMetaData();
    ResultSet resultSet = dbmd.getTypeInfo();

    while (resultSet.next()) {
        // Get the database-specific type name
        String typeName = resultSet.getString("TYPE_NAME");

        short dataType = resultSet.getShort("DATA_TYPE");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);//  w  w w .  j  a v a2 s. c o  m

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    DatabaseMetaData dbmd = connection.getMetaData();
    ResultSet resultSet = dbmd.getTypeInfo();

    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");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getMySqlConnection();
    System.out.println("Got Connection.");
    Statement st = conn.createStatement();
    st.executeUpdate("drop table survey;");
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");

    ResultSet rs = null;/*from   w ww  .j  a v  a2s.c  o  m*/
    DatabaseMetaData meta = conn.getMetaData();
    rs = meta.getTypeInfo();
    while (rs.next()) {
        // Get the database-specific type name
        String typeName = rs.getString("TYPE_NAME");

        // Get the java.sql.Types type to which this
        // database-specific type is mapped
        short dataType = rs.getShort(2);

        // Get the name of the java.sql.Types value.
        System.out.println("type name=" + typeName);
        System.out.println("dataType=" + dataType);
        System.out.println("jdbcType=" + dataType);
    }
    st.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getMySqlConnection();
    System.out.println("Got Connection.");
    Statement st = conn.createStatement();
    st.executeUpdate("drop table survey;");
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");

    ResultSet rs = null;// w w w.  j av  a  2  s.co  m
    DatabaseMetaData meta = conn.getMetaData();
    rs = meta.getTypeInfo();
    while (rs.next()) {
        // Get the database-specific type name
        String typeName = rs.getString("TYPE_NAME");

        // Get the java.sql.Types type to which this
        // database-specific type is mapped
        short dataType = rs.getShort("DATA_TYPE");

        // Get the name of the java.sql.Types value.
        System.out.println("type name=" + typeName);
        System.out.println("dataType=" + dataType);
        System.out.println("jdbcType=" + dataType);
    }
    st.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);/*from   ww  w  .j  ava  2s  . c o  m*/

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    DatabaseMetaData dbmd = connection.getMetaData();
    ResultSet resultSet = dbmd.getTypeInfo();

    while (resultSet.next()) {
        String typeName = resultSet.getString("TYPE_NAME");

        short dataType = resultSet.getShort("DATA_TYPE");
        getJdbcTypeName(dataType);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);/* ww w .  ja va 2s .com*/

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    DatabaseMetaData dbmd = connection.getMetaData();
    ResultSet resultSet = dbmd.getTypeInfo();

    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");
        getJdbcTypeName(dataType);
    }
}

From source file:TypeInfo.java

public static void main(String args[]) {

    String url = "jdbc:mySubprotocol:myDataSource";
    Connection con;/*from   ww  w . j  a  va2s  .co m*/
    DatabaseMetaData dbmd;

    try {
        Class.forName("myDriver.ClassName");

    } catch (java.lang.ClassNotFoundException e) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(e.getMessage());
    }

    try {
        con = DriverManager.getConnection(url, "myLogin", "myPassword");

        dbmd = con.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("");

        }

        con.close();

    } catch (SQLException ex) {
        System.err.println("SQLException: " + ex.getMessage());
    }
}