将数据插入mysql数据库表时出错 [英] Error Inserting Data into mysql database's table
本文介绍了将数据插入mysql数据库表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试将数据插入到mysql数据库表中时,我收到以下错误值附近的mysql语句中的语法错误(。我不知道如何解决此问题。源代码如下所示。
如果你能解决我的问题!
谢谢。
私人 void cmdAddDataActionPerformed(java.awt.event.ActionEvent evt){
// TODO在此添加处理代码:
字符串 ItCode = txtICode.getText();
字符串 ItType = txtIType.getText();
int ItSize = Integer.parseInt (txtISize.getText());
String ItName = txtIName.getText();
String ItColour = txtIColor.getText();
int InStock = Integer.parseInt(txtIStock.getText());
double ItPrice = Double.parseDouble(txtIPrice.getText());
conn = DbConn.ConnDB();
String sql;
sql = INSERT INTO ITEMDETAILS(
+ ItemCode,
+ ItemType,
+ ItemSize,
+ ItemName,
+ ItemColour,
+ InStock,
+ ItemPrice)
VALAUES( ' + ItCode + ',' + ItType + ', + ItSize + ,' + ItName + ',' + ItColour + ', + InStock + ,' + ItPrice + < span class =code-string> ');
try {
ps = conn.prepareStatement(sql);
ps.execute();
JOptionPane.showMessageDialog(null,已保存 );
UpdateJTable();
//conn.close();
} catch(例外e){
JOptionPane.showMessageDialog(null,e);
}
}
解决方案
拼写错误引用:VALAUES
它应该是值。
祝你好运
正确的MySQL声明如下。
sql = INSERT INTO ITEMDETAILS(
+ ItemCode,
+ ItemType,
+ ItemSize,
+ ItemName,
+ ItemColour,
+ InStock,
+ ItemPrice) + VALUES( + txtICode.getText()+ ,' + txtIType.getText()+ ',' + txtISize.getText()+ ',' + txtIName.getText()+ ',' + txtIColor.getText()+ ',' + txtIStock.getText()+ ',' + txtIPrice.getText()+ ')跨度>;
When I am trying to insert data into a mysql database table I got the following error "Syntax error in your mysql statement near Values(". I don''t know how to fix this matter. The source code is stated at the below.
If you could please solve my problem!
Thank You.
private void cmdAddDataActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String ItCode = txtICode.getText();
String ItType = txtIType.getText();
int ItSize = Integer.parseInt(txtISize.getText());
String ItName = txtIName.getText();
String ItColour = txtIColor.getText();
int InStock = Integer.parseInt(txtIStock.getText());
double ItPrice = Double.parseDouble(txtIPrice.getText());
conn = DbConn.ConnDB();
String sql;
sql = "INSERT INTO ITEMDETAILS("
+ "ItemCode,"
+ "ItemType,"
+ "ItemSize,"
+ "ItemName,"
+ "ItemColour,"
+ "InStock,"
+"ItemPrice)
VALAUES('" + ItCode + "','" + ItType + "'," + ItSize +",'" + ItName + "','"+ ItColour +"'," + InStock + ",'"+ ItPrice + "');
try {
ps = conn.prepareStatement(sql);
ps.execute();
JOptionPane.showMessageDialog(null, "Saved");
UpdateJTable();
//conn.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
解决方案
Hi,
Incorrect spellQuote:VALAUES
it should be values.
best luck
The Correct MySQL statement is at below.
sql = "INSERT INTO ITEMDETAILS(" + "ItemCode," + "ItemType," + "ItemSize," + "ItemName," + "ItemColour," + "InStock," +"ItemPrice)" + "VALUES(" + txtICode.getText() + ",'" + txtIType.getText() + "','" + txtISize.getText() + "','" + txtIName.getText() + "','"+ txtIColor.getText() + "','" + txtIStock.getText() + "','" + txtIPrice.getText() + "')";
这篇关于将数据插入mysql数据库表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文