我的Jtable
已连接到我创建的数据库,因此它可以在我的GUI中显示所有数据。但我试图从我的JTable的数据获取到JTextField。就像当你点击表格的行时,表格中的数据将进入TextField。但是,当我点击表它显示了这样的错误:无法将数据从JTable数据库提取到JTextField
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您在您的SQL语法错误 ;检查对应于您 MariaDB的服务器版本正确的语法使用近“NO。=” 1 拉舍尔”在1号线
我一直在寻找答案的手册,但我无法找到之一。请帮我自上周五以来,我一直坚持这个错误。
table = new JTable();
scrollPane.setViewportView(table);
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int row = table.getSelectedRow();
String table_click = (table.getModel().getValueAt(row, 0).toString());
try {
String query = "SELECT * FROM `raschel` where MACHINE NO.='" + table_click + "'";
Connection con;
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
String machine = rs.getString("MACHINE NO.");
String type = rs.getString("TYPE");
String product = rs.getString("PRODUCT");
txtMachine.setText(machine);
txtType.setText(type);
txtProd.setText(product);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
});
天啊。谢谢!这工作。由于我的挫折,我没有看到这个错误。再次感谢answe。 :) –
@JeffRolanGoyalYñota不客气 – Jens
我不能upvote,因为我的声誉是0. Im new here。 :( –