我想将数据添加MySql
到JTable
. 我只是写了这个简单的代码来做到这一点,但它不起作用。
Properties props = new Properties();
props.put("user", "root");
props.put("password", "password");
props.put("useUnicode", "true");
props.put("characterEncoding", "UTF-8");
props.put("useServerPrepStmts", "false");
props.put("characterEncoding", "UTF-8");
url = "jdbc:mysql://localhost/library_System";
Connection conn = (Connection) DriverManager.getConnection(url, props);
Statement stmt = (Statement) conn.createStatement();
String SQL = "select * from library_system";
ResultSet rs = stmt.executeQuery(SQL);
DefaultTableModel model = new DefaultTableModel();
model.addColumn("Name");
model.addColumn("Email");
JTable table = new JTable(model);
table.setSize(Int2.getWidth(), Int2.getHeight());
panel3.add(table);
while(rs.next())
{
model.addRow(new Object[]{rs.getString("Full_Name"), rs.getString("Email")});
}