日期:2014-05-16  浏览次数:20368 次

java获得数据库主键信息
public String getPrimaryName(Connection conn)  throws Exception{
		DatabaseMetaData md = conn.getMetaData();
		ResultSet rs = md.getPrimaryKeys(null, null, "gsm_alert_check");
		while(rs.next()){
			System.out.println(rs.getString("TABLE_CAT"));
			System.out.println(rs.getString("TABLE_SCHEM"));
			System.out.println(rs.getString("TABLE_NAME"));
			System.out.println(rs.getString("COLUMN_NAME"));
			System.out.println(rs.getString("KEY_SEQ"));
			System.out.println(rs.getString("PK_NAME"));
		}
		
		rs.close();
		return null;
	}