Connection conn = DriverManager.getConnection(url,userName,password);
//實現關於數據庫的整體綜合信息對象:如下:
java.sql.DatabaseMetaData dbmd=conn.getMetaData();
//獲取數據庫相關的信息,
System.out.println("數據庫產品名: "+dbmd.getDatabaseProductName());
System.out.println("數據庫是否支持事務: "+dbmd.supportsTransactions());
System.out.println("數據庫產品的版本號:"+dbmd.getDatabaseProductVersion());
//獲取全表相關的信息
ResultSet tSet=dbmd.getTables(null,"%","%",newString[]{"TABLE","VIEW"})
while(tSet.next()){
System.out.println(tSet.getRow()+"_表類別:"+tSet.getString("TABLE_CAT")+"_表模式:"+tSet.getString ("TABLE_SCHEM")+"_表名稱:"+tSet.getString("TABLE_NAME")+"_表類型:"+tSet.getString("TABLE_TYPE")
}
//獲取表的主鍵列信息;
ResultSetprimaryKey=dbmd.getPrimaryKeys("MANOR","PUBLIC","SYS_ROLE_RES");
while(primaryKey.next()){
System.out.println("表名:"+primaryKey.getString("TABLE_NAME")+",列名:"+primaryKey.getString("COLUMN_NAME")
+" 主鍵名:"+primaryKey.getString("PK_NAME"));
//其中表名:SYS_ROLE_RES,
}
//獲取表的外鍵列信息"
ResultSet foreinKey=dbmd.getImportedKeys("MANOR","PUBLIC","SYS_ROLE_RES");
while(foreinKey.next()){
System.out.println("主鍵名:"+foreinKey.getString("PK_NAME")+",外鍵名:"+foreinKey.getString("FKCOLUMN_NAME")
+",主鍵表名:"+foreinKey.getString("PKTABLE_NAME")+",外鍵表名:"+foreinKey.getString("FKTABLE_NAME")
+",外鍵列名:"+foreinKey.getString("PKCOLUMN_NAME")+",外鍵序號:"+foreinKey.getString("KEY_SEQ"));
}
相獲取更多SQL參數,可參考數據庫相關方面的教材。