我遇到了Sql语法错误com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '8 , 0' at line 1
,(我通过输入获取属性),例如,我在mysql中插入表:
插入itshop
。supply
(id
,idSupplier
,dateTime
,quantity
,totalCost
)VALUES( '2', '4', '2009-1-4', '24', '245');
int rs2 = st2.executeUpdate("INSERT INTO supply VALUES ( "
+ id + " , " + idSupplier + " , "
+ dateTime + " , " + idProduct + " ,"
+ Quantity + " , " + price + "");
if (rs2 == 1) {
JOptionPane.showMessageDialog(Sale,
"Product Ordered", "Supply",
JOptionPane.DEFAULT_OPTION);
}
您需要''
像这样保持varchar类型
int rs2 = st2.executeUpdate("INSERT INTO supply VALUES ( '"
+ id + " ',' " + idSupplier + "' , '"
+ dateTime + " ', '" + idProduct + " ','"
+ Quantity + " ', '" + price + "'");
使用PreparedStatement代替Statement,这消除了混淆'
简单的例子
PreparedStatement pt=connection.prepareStatement(insert into test values(?,?));
pt.setString(1,"hi");
pt.setInt(2,1);
pt.executeUpdate();
对于您的插入操作,PreparedStatemet将为
PreparedStatement pt=connection.prepareStatement("INSERT INTO supply VALUES (?,?,?,?,?,?)")
pt.setString(1,id );
pt.setString(2,idSupplier );
pt.setString(3,dateTime );
pt.setString(4,idProduct );
pt.setString(5,Quantity );
pt.setString(6,price );
int rs2=pt.executeUpdate();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句