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;
}
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码