@Test public void rrs(){ try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select id ID,name 姓名,score 成绩 from st 学生"); ResultSetMetaData rsm = rs.getMetaData(); System.out.println(rsm.getColumnCount()); //表的列数 System.out.println(rsm.getTableName(1)); //表名 for(int i =1; i<=rsm.getColumnCount();i++){ System.out.println("-".repeat(80)); System.out.println(rsm.getColumnName(i)); //表的字段名 System.out.println(rsm.getColumnLabel(i)); //表的别名 System.out.println(rsm.getColumnType(i)); //列的类型,数字表示 System.out.println(rsm.getColumnTypeName(i)); //列的类型,字符串表示 System.out.println(rsm.getCatalogName(i)); //数据库名 } } catch (SQLException throwables) { throwables.printStackTrace(); } }