我的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。 :( –