Java JDBC Database Metadata getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName)

Here you can find the source of getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName)

Description

Returns the default value of a column (as per its SQL definition).

License

Open Source License

Parameter

Parameter Description
metaData the database meta data
tableName the name of the table in which the column is
columnName the name of the column to check

Exception

Parameter Description
SQLException :)

Return

the default value of the column (may be null)

Declaration

public static Object getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName)
        throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    /**//from   w  w  w  .j  av a  2s . c om
     * Returns the default value of a column (as per its SQL definition).
     *
     * @param metaData the database meta data
     * @param tableName the name of the table in which the column is
     * @param columnName the name of the column to check
     * @return the default value of the column (may be null)
     * @throws SQLException :)
     */
    public static Object getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName)
            throws SQLException {
        try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
            if (!rs.next()) {
                throw new IllegalStateException(
                        "Did not find meta data for column '" + columnName + "' while checking its default value");
            }
            return rs.getObject("COLUMN_DEF");
        }
    }
}

Related

  1. adjustIdentifierCase(String identifier, Connection conn)
  2. createHsqlPlSchemaIfNecessary(Connection con)
  3. getAllTables(Connection connection)
  4. getAllTables(Connection connection)
  5. getCatalogs(Connection c)
  6. getColumnNames(Connection connection, String tableName)
  7. getColumnNames(String tablename, String column, Connection conn)
  8. getColumns(Connection connection, String name)
  9. getColumnSize(Connection con, String tableName, String columnName)