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")});
}