您好,登錄后才能下訂單哦!
public class DataBaseMessage {
public static void main(String[] args) {
getMessage();
}
public static void getMessage(){
Connection connection = null;
ResultSet rs = null;
try {
connection = 獲取connection;
DatabaseMetaData dbMetaData = connection.getMetaData();
System.out.println("數據庫相關信息 : ");
System.out.println("已知的用戶: "+ dbMetaData.getUserName());
System.out.println("系統函數的逗號分隔列表: "+ dbMetaData.getSystemFunctions());
System.out.println("時間和日期函數的逗號分隔列表: "+ dbMetaData.getTimeDateFunctions());
System.out.println("字符串函數的逗號分隔列表: "+ dbMetaData.getStringFunctions());
System.out.println("供應商用于 'schema' 的首選術語: "+ dbMetaData.getSchemaTerm());
System.out.println("URL: " + dbMetaData.getURL());
System.out.println("是否允許只讀:" + dbMetaData.isReadOnly());
System.out.println("的產品名稱:" + dbMetaData.getDatabaseProductName());
System.out.println("版本:" + dbMetaData.getDatabaseProductVersion());
System.out.println("驅動程序的名稱:" + dbMetaData.getDriverName());
System.out.println("驅動程序的版本:" + dbMetaData.getDriverVersion());
//查詢t_file表格的所有信息
rs = dbMetaData.getColumns(null, null,"表名稱", null);
//獲取t_file表每條記錄的信息
while(rs.next()){
System.out.println();System.out.println();
String column_name = rs.getString("COLUMN_NAME");
String type_name = rs.getString("TYPE_NAME");
int column_size = rs.getInt("COLUMN_SIZE");
boolean is_nullable = rs.getBoolean("IS_NULLABLE");
String column_def = rs.getString("COLUMN_DEF");
System.out.println("column_name :"+column_name+" **** type_name :"+type_name+" **** column_size : "+column_size+" **** is_nullable : "+is_nullable +" **** column_def : "+column_def);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
//connection.close();
//rs.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。