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 '1,'??‰?????”??‰','35',1,35)' at line 1
代码是这样的:
//插入书籍
public boolean InsertBook(String userid,Book b){
conn = DB.getCon(); //获取数据库连接
System.out.println(userid);//userid是表名,是中文字符的
if(conn!=null){
try {
String sql="insert into "+userid+"values(?,?,?,?,?)";
PreparedStatement pstm=conn.prepareStatement(sql);
pstm.setInt(1, b.getBookId());
System.out.println(b.getName());//值是'三国演义'
pstm.setString(2, b.getName());//书的名字是中文字符的
pstm.setString(3, b.getPrice());
pstm.setInt(4, 1);
pstm.setInt(5, Integer.parseInt(b.getPrice()));
System.out.println("语句没错");
pstm.executeUpdate();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return false;
}
代码是这样的:
//插入书籍
public boolean InsertBook(String userid,Book b){
conn = DB.getCon(); //获取数据库连接
System.out.println(userid);//userid是表名,是中文字符的
if(conn!=null){
try {
String sql="insert into "+userid+"values(?,?,?,?,?)";
PreparedStatement pstm=conn.prepareStatement(sql);
pstm.setInt(1, b.getBookId());
System.out.println(b.getName());//值是'三国演义'
pstm.setString(2, b.getName());//书的名字是中文字符的
pstm.setString(3, b.getPrice());
pstm.setInt(4, 1);
pstm.setInt(5, Integer.parseInt(b.getPrice()));
System.out.println("语句没错");
pstm.executeUpdate();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return false;
}
解决方案 »
- 用mysqldump导出整个数据库时,能不能不导某些表数据?(顶有分)
- 帮我看看有那个字段不应该放在这个表。
- 求一个inner join语句
- mysqld_safe起动服务错误
- mysql建表,想设定email字段是唯一(一个email注册一个ID),怎么设定?
- 为什么不能在图形界面上操作了?
- 请问不能用函数设置表的初始时间么create table f (birthday datetime not null default concat(current_date(),' ',current_time()));
- linux下的mysql
- 请教一个mysql保留字的简单问题
- MySQL事件
- 存储过程分为两个部分单独测试没问题,写到一起出错
- 求一个 mysql 查询分组与塞选 语句
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码