我们想要建立一个医疗信息系统。在这个制度下,我们必须买药。当用户购买药品时,他/她必须输入条形码和购买药品的号码。我们希望获取要服用的药物数量,并将此值添加到SQL表中。但我们有个错误。
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '10013''where Barcode='10013'' at line 1这是我的代码:BuyMedicine.java
..。
BarcodeField = new JTextField();
BarcodeField.setBounds(130, 26, 294, 21);
contentPane.add(BarcodeField);
BarcodeField.setColumns(10);
NumberField = new JTextField();
NumberField.setBounds(130, 86, 294, 21);
contentPane.add(NumberField);
NumberField.setColumns(100);
JButton btnBuy = new JButton("Buy");
btnBuy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root","");
Statement stmt = con.createStatement();
String x = "Select Stock from medicinelist where Barcode='" + BarcodeField.getText()+"'";
PreparedStatement preparedStmt2 = con.prepareStatement(x);
preparedStmt2.execute();
String sql = "Update medicinelist set Stock='" +Integer.parseInt(NumberField.getText())+x
+"'where Barcode='"+ BarcodeField.getText()+"'";
PreparedStatement preparedStmt = con.prepareStatement(sql);
preparedStmt.executeUpdate();
JOptionPane.showMessageDialog(null, "Done!!!");
con.close();
}catch(Exception e) { System.out.print(e);}
}
});..。
发布于 2018-12-27 09:36:47
在查询中
'" +Integer.parseInt(NumberField.getText())+ x +"'where 放置+“'在x后面的查询如下
'" +Integer.parseInt(NumberField.getText())+"'"+ x +" where并为干净的查询留出空间。
发布于 2018-12-27 11:06:56
字符串x=“从医药列表中选择股票,其中Barcode=‘+BarcodeField.getText()+’‘;
和
String sql = "Update set Stock='“+Integer.parseInt(NumberField.getText())+x +”Barcode='"+ BarcodeField.getText()+"'";
所以string sql变成
String sql = "Update set Stock='“从Barcode=‘’+BarcodeField.getText()+‘’BarcodeField.getText+ Barcode='"+ BarcodeField.getText()+‘’”的医药列表中获得的股票;
错误也是如此:)
在结果集中收集"string x“查询输出,并在"string”中使用它。
发布于 2018-12-27 09:22:41
+"'where Barcode='"+ BarcodeField.getText()+"'";单引号和之间没有空格,其中。提供它,然后再运行。
https://stackoverflow.com/questions/53941482
复制相似问题