62,612
社区成员
发帖
与我相关
我的任务
分享
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 '33'asdfasdf''1987-1-1')' at line 1com.mysql.jdbc.exceptions.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 '33'asdfasdf''1987-1-1')' at line 1
public void button2_actionPerformed(ActionEvent e){
int sl;
String bianhao = jtbianhao.getText().trim();
String zuozhe = jtzuozhe.getText().trim();
String shuliang = jtshuliang.getText().trim();
String shuming = jtshuming.getText().trim();
String chubanshe = jtchubanshe.getText().trim();
String ruku = jtdate.getText().trim();
if(bianhao.equals(""))
JOptionPane.showMessageDialog(null, "图书编号不能为空,请继续填写```", "信息填写错误",
JOptionPane.ERROR_MESSAGE);
else if (zuozhe.equals(""))
JOptionPane.showMessageDialog(null, "图书作者不能为空,请继续填写```", "信息填写错误",
JOptionPane.ERROR_MESSAGE);
else if(shuliang.equals(""))
JOptionPane.showMessageDialog(null, "图书数量不能为空,请继续填写```", "信息填写错误",
JOptionPane.ERROR_MESSAGE);
else if(shuming.equals(""))
JOptionPane.showMessageDialog(null, "图书名称不能为空,请继续填写```", "信息填写错误",
JOptionPane.ERROR_MESSAGE);
else if(chubanshe.equals(""))
JOptionPane.showMessageDialog(null, "出版社不能为空,请继续填写```", "信息填写错误",
JOptionPane.ERROR_MESSAGE);
else if(ruku.equals(""))
JOptionPane.showMessageDialog(null, "入库时间不能为空,请继续填写```", "信息填写错误",
JOptionPane.ERROR_MESSAGE);
else{
try {
sl = Integer.parseInt(shuliang);
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "图书的 数量 只能是数字!!!,请继续填写```",
"数量填写错误",
JOptionPane.ERROR_MESSAGE);
return;
}
String sql = "insert into booksinfo (bookid,bookname,bookauthor,num,publisher,begintime) values(??????)";
PreparedStatement pe=null;
ResultSet rs=null;
try {
pe = db.conn.prepareStatement(sql);
pe.setString(1, bianhao);
pe.setString(2, shuming);
pe.setString(3, zuozhe);
pe.setInt(4, sl);
pe.setString(5, chubanshe);
pe.setString(6, ruku);
if(db.add(pe)){
db.myClose(1);
JOptionPane.showMessageDialog(null, "增加成功");
}
else
JOptionPane.showMessageDialog(null, "添加失败");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
public boolean add(PreparedStatement pt)
{
int result=-1;
try {
result = pt.executeUpdate();
} catch (SQLException ex) {
System.out.println(ex.toString());
ex.printStackTrace();
}
if(result>0)
return true;
else
return false;
}