Java获取数据库表的字段及类型

public static Map getmap(String synonymsName(表名)) {

Map map = new HashMap(); Connection ct = null; Statement sm = null; ResultSet rs = null; try {

// 加载驱动

Class.forName(\);

// 得到连接

ct = DriverManager.getConnection(

\, \,

\);

sm = ct.createStatement();

String sql = \ + synonymsName + \;

rs = sm.executeQuery(sql);

ResultSetMetaData md = rs.getMetaData(); for (int i = 1; i <= md.getColumnCount(); i++) {

map.put(md.getColumnName(i), md.getColumnTypeName(i)); }

} catch (Exception e) { e.printStackTrace(); } finally { try {

rs.close(); sm.close(); ct.close();

} catch (Exception e) { e.printStackTrace(); } }

return map;

}

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4