以下代码可能正常工作,列名称显示为
JScrollPane sp = new JScrollPane(table);
frame.add(sp, BorderLayout.CENTER);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, user, password);
String str = "select * from patient ";
PreparedStatement pst = conn.prepareStatement(str);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception exc) {
exc.printStackTrace();
}
但是使用此代码时,列名称不可见
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, user, password);
String str = "select * from staff";
PreparedStatement pst = conn.prepareStatement(str);
ResultSet rs = pst.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception exc) {
你可以帮我吗?
谢谢