這是用戶在程序啓動後將插入數據的textField的代碼。它不更新mysql表。爲什麼它不起作用?插入數據的用戶已經進入mysql(java)
textField = new JTextField();
textField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/csprogram","root","");
price=scan.next();
String query = "INSERT * INTO `graphics` (price (KM)) VALUES (?);";
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setString (1, price);
preparedStmt.executeUpdate();
}
catch (Exception d) {
System.out.println("Error found "+ d);
}
}
});
你必須在'INSERT'無效的語法。嘗試使用'「插入圖形(價格)VALUES(?)」'併發布錯誤消息,如果它仍然無法正常工作。 –
'graphics'的表格定義如何? –
我可能需要更新表格內的所有列嗎?因爲價格(KM)是其中之一8.它不顯示任何程序的錯誤消息。它只是凍結程序,我不得不停止控制檯。我應該如何獲得表格定義,我沒有在我的代碼中? – Ibrahimf