[求助]写入sql语句insert失败了.(只有这句失败了)
private void addBookBtnActionPerformed(ActionEvent e){
boolean okSet=true;
int avaNum=0,sellNum=0;
String id=idText.getText();
String name=bNameText.getText();
String writer=writerText.getText();
String publisher=publisherText.getText();
String key=keyWText.getText();
try{
avaNum=Integer.parseInt(avaNumText.getText());
}
catch(
NumberFormatException ee){
okSet=false;
JOptionPane.showMessageDialog(this,"库存格式错误!","警告",JOptionPane.CANCEL_OPTION);
}
try{
sellNum=Integer.parseInt(sellNumText.getText());
}
catch(NumberFormatException ee){
okSet=false;
JOptionPane.showMessageDialog(this,"售货量格式错误!","警告",JOptionPane.CANCEL_OPTION);
}
if(okSet==true){
boolean insertFaile=false;
try{
stamt=connect.createStatement();
stamt.executeUpdate("insert into BookInfo (编号,商品名,类别,产地,关键字,库存,售货量) values("+id+"','"+name+"','"+writer+"','"+publisher+"','"+key+"',"+avaNum+"',"+sellNum+")");
//////////////////////////////////////////////这句只插入编号就正常,其他无论如何插入都失败- -..我实在找不出问题.求解.user表中有编号,商品名,类别,产地,关键字,库存,售货量
}
catch(Exception ee){
insertFaile=true;
JOptionPane.showMessageDialog(this,"由于此编号已存在或其他未可知原因造成此次操作失败!","警告",JOptionPane.CANCEL_OPTION);
}
if(!insertFaile){
JOptionPane.showMessageDialog(this,"恭喜!\n数据成功加入数据库!","提示",JOptionPane.OK_OPTION);
clearAddBookText();
}
}
}
------解决方案--------------------stamt.executeUpdate("insert into BookInfo (编号,商品名,类别,产地,关键字,库存,售货量) values("+id+",\'"+name+"\',\'"+writer+"\',\'"+publisher+"\',\'"+key+"\',"+avaNum+","+sellNum+")");
注意单引号要用转义符\
------解决方案--------------------感觉单引号用的很混乱啊。。。是不是这个引起的
------解决方案--------------------"+id+"','"+name+"
id后面多了一个'吧?