大家好,又见面了,我是你们的朋友全栈君。
try {
String user = “ahcwtest”;
String password = “ahcwtest”;
String driver= “oracle.jdbc.driver.OracleDriver”;
String url= “jdbc:oracle:thin:@192.168.71.17:1521:orcl”;
String sql = “SELECT A FROM A”;
Class.forName(driver).newInstance();
Connection c = DriverManager.getConnection(url, user, password);
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(sql);
DatabaseMetaData dbmd = c.getMetaData();
ResultSet pk = dbmd.getPrimaryKeys(null, null, “A”);
while( pk.next() ) {
System.out.println(“表A”);
System.out.println(“PKTABLE_CAT:”+pk.getObject(1));
System.out.println(“PKTABLE_SCHEM:”+pk.getObject(2));
System.out.println(“PKTABLE_NAME:”+pk.getObject(3));
System.out.println(“COLUMN_NAME:”+pk.getObject(4));
System.out.println(“KEY_SEQ:”+pk.getObject(5));
System.out.println(“PK_NAME:”+pk.getObject(6));
}
ResultSet t = dbmd.getCatalogs();
while (t.next()) {
System.out.println(t.getString(0));
}
// while (rs.next()) {
// System.out.println(rs.getString(1));
// }
} catch (Exception e) {
e.printStackTrace();
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/151218.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...