数据库问题,用MYSQL往表中插入数据出错(含错误代码)

liang__ 2008-06-19 04:52:44
下面这个是我的表。用的是MySql数据库
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;
}
...全文
424 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanlingyun 2008-06-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 liang__ 的回复:]
分还继续给。
33楼给10分
66楼分40分
99楼分50分
[/Quote]
拜托,这里不是散分区,建议你无满意结贴
kuyesuifeng 2008-06-19
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 SatByBed 的回复:]
爱给不给,你看着办吧。。。
[/Quote]
SatByBed 2008-06-19
  • 打赏
  • 举报
回复
爱给不给,你看着办吧。。。
liang__ 2008-06-19
  • 打赏
  • 举报
回复
我怎么会是个托?
我只是个学生好不?
我正在做一个图书管理系统。这里面是我遇到的错误,
只是碰巧又让我找到错误了。晕。。
TRMeister 2008-06-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liang__ 的回复:]
对不住各位了,我发现了错误,是不细心造成的。
所以就没分了。
String sql = "insert into booksinfo (bookid,bookname,bookauthor,num,publisher,begintime) values(??????)";
这个位置少了逗号
[/Quote]

原来是个托。受骗了。
TRMeister 2008-06-19
  • 打赏
  • 举报
回复
少,号
insert into booksinfo (bookid,bookname,bookauthor,num,publisher,begintime) values(?,?,?,?,?,?);
kuyesuifeng 2008-06-19
  • 打赏
  • 举报
回复
(??????)---->
(?,?,?,?,?,?)
liang__ 2008-06-19
  • 打赏
  • 举报
回复
分还继续给。
33楼给10分
66楼分40分
99楼分50分
laorer 2008-06-19
  • 打赏
  • 举报
回复
..看代码,头错了,一般碰到这问事,你最好把生成的sql sysout出来,然后在查询分析器之类的环境中执行下它
liang__ 2008-06-19
  • 打赏
  • 举报
回复
对不住各位了,我发现了错误,是不细心造成的。
所以就没分了。
String sql = "insert into booksinfo (bookid,bookname,bookauthor,num,publisher,begintime) values(??????)";
这个位置少了逗号

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧