数据库问题,用MYSQL往表中插入数据出错(含错误代码)
下面这个是我的表。用的是MySql数据库
create table booksInfo(bookid varchar(20), bookname varchar(30),bookauthor varchar(20),num int,publisher varchar(50) , begintime datetime);
而我在做往表中插入数据时出现错误,
错误代码:
部分JAVA代码:
create table booksInfo(bookid varchar(20), bookname varchar(30),bookauthor varchar(20),num int,publisher varchar(50) , begintime datetime);
而我在做往表中插入数据时出现错误,
错误代码:
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部分JAVA代码:
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;
}
...全文
相关推荐
数据库错误代码和消息
数据库错误代码和消息
SQL错误代码汇总:MySQL
鉴于MySQL的灵活性和广泛应用,对常见错误代码的了解可以提高我们的数据库开发和管理技能。解释:这个错误表示在创建外键约束时,引用的外键列的值与被引用的主键列的值不匹配。解决方法是确保外键列的值与主键列的值匹配,或者在创建外键约束时使用ON UPDATE和ON DELETE选项来处理相关的更新和删除操作。解释:这个错误表示在查询中引用了不存在的列名。解决方法是检查列名的拼写和引用方式,并确保它存在于查询的表或视图中。解决方法是确保插入的值是唯一的,或者更新已存在的记录。错误信息:外键约束失败。
mysql错误文档.doc
mysql错误文档.doc
MySQL常见出错代码速查表
PHP连接MySQL数据库时出现的错误代码的含义基本都可以找到,非常有助于解决问题。
MYSQL ERROR CODE 错误编号的意义.docx
...


Java SE
