Here you can find the source of getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName)
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 |
Parameter | Description |
---|---|
SQLException | :) |
public static Object getColumnDefaultValue(DatabaseMetaData metaData, String tableName, String columnName) throws SQLException
//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"); } } }