本文整理汇总了Java中java.sql.DatabaseMetaData.getVersionColumns方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMetaData.getVersionColumns方法的具体用法?Java DatabaseMetaData.getVersionColumns怎么用?Java DatabaseMetaData.getVersionColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.DatabaseMetaData
的用法示例。
在下文中一共展示了DatabaseMetaData.getVersionColumns方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetVersionColumns
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Test public void testGetVersionColumns() throws SQLException {
DatabaseMetaData metadata = getDatabaseMetadata();
try (ResultSet rs = metadata.getVersionColumns(null, null, null)) {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(8, rsMeta.getColumnCount());
assertColumn(rsMeta, 1, "SCOPE", Types.SMALLINT, DatabaseMetaData.columnNullableUnknown);
assertColumn(rsMeta, 2, "COLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 3, "DATA_TYPE", Types.INTEGER, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 4, "TYPE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 5, "COLUMN_SIZE", Types.INTEGER, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 6, "BUFFER_LENGTH", Types.INTEGER, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 7, "DECIMAL_DIGITS", Types.SMALLINT, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 8, "PSEUDO_COLUMN", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
}
}
示例2: runOtherMetaDataTests
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void runOtherMetaDataTests() throws SQLException
{
DatabaseMetaData metadata = connection.getMetaData();
try (ResultSet rs = metadata.getCatalogs())
{
}
try (ResultSet rs = metadata.getAttributes("", "", null, null))
{
}
try (ResultSet rs = metadata.getClientInfoProperties())
{
}
try (ResultSet rs = metadata.getFunctionColumns("", "", null, null))
{
}
try (ResultSet rs = metadata.getFunctions("", "", null))
{
}
try (ResultSet rs = metadata.getProcedureColumns("", "", null, null))
{
}
try (ResultSet rs = metadata.getProcedures("", "", null))
{
}
try (ResultSet rs = metadata.getSchemas())
{
}
try (ResultSet rs = metadata.getSchemas("", null))
{
}
try (ResultSet rs = metadata.getSuperTypes("", "", null))
{
}
try (ResultSet rs = metadata.getTableTypes())
{
}
try (ResultSet rs = metadata.getTypeInfo())
{
}
try (ResultSet rs = metadata.getUDTs(null, null, null, null))
{
}
for (String table : TABLES)
{
try (ResultSet rs = metadata.getExportedKeys("", "", table))
{
}
try (ResultSet rs = metadata.getImportedKeys("", "", table))
{
}
try (ResultSet rs = metadata.getBestRowIdentifier("", "", table, DatabaseMetaData.bestRowTransaction,
false))
{
}
try (ResultSet rs = metadata.getColumnPrivileges("", "", table, null))
{
}
try (ResultSet rs = metadata.getPrimaryKeys("", "", table))
{
}
try (ResultSet rs = metadata.getPseudoColumns("", "", table, null))
{
}
try (ResultSet rs = metadata.getSuperTables("", "", table))
{
}
try (ResultSet rs = metadata.getTablePrivileges("", "", table))
{
}
try (ResultSet rs = metadata.getVersionColumns("", "", table))
{
}
}
}
示例3: testTimestamp
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void testTimestamp(Connection con, Statement st, String dbname) throws SQLException {
boolean explicitDefaultsForTimestamp = false;
if (versionMeetsMinimum(8, 0, 2)) {
String v = getMysqlVariable("explicit_defaults_for_timestamp");
if ("ON".equals(v)) {
explicitDefaultsForTimestamp = true;
}
}
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)");
DatabaseMetaData dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
if (explicitDefaultsForTimestamp) {
assertFalse("0 column must be found", this.rs.next());
} else {
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));
}
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertFalse("0 column must be found", this.rs.next());
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT 0)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertFalse("0 column must be found", this.rs.next());
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", "f1", this.rs.getString(2));
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP NULL, f2 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", "f2", this.rs.getString(2));
// ALTER test
st.execute("ALTER TABLE testBug63800 CHANGE COLUMN `f2` `f2` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', "
+ "ADD COLUMN `f3` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP AFTER `f2`");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", "f3", this.rs.getString(2));
}
示例4: testTimestamp
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void testTimestamp(Connection con, Statement st, String dbname) throws SQLException {
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)");
DatabaseMetaData dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertFalse("0 column must be found", this.rs.next());
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT 0)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertFalse("0 column must be found", this.rs.next());
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f1");
st.execute("DROP TABLE IF EXISTS testBug63800");
st.execute("CREATE TABLE testBug63800(f1 TIMESTAMP NULL, f2 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP)");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f2");
// ALTER test
st.execute("ALTER TABLE testBug63800 CHANGE COLUMN `f2` `f2` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', "
+ "ADD COLUMN `f3` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP AFTER `f2`");
dmd = con.getMetaData();
this.rs = dmd.getVersionColumns(dbname, dbname, "testBug63800");
assertTrue("1 column must be found", this.rs.next());
assertEquals("Wrong column or single column not found", this.rs.getString(2), "f3");
}