java.sql.SQLException: No value specified for parameter 1
解决方法:
String msg="你好!'再见'";
String sql = "INSERT INTO tb_log (message_content) VALUES('"+msg+"')" ;
执行sql就会报上面错误,单引号混乱引起的参数识别错误。
修改:
String sql = "INSERT INTO tb_log (message_content) VALUES(?)" ;
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setObject(1, msg);//1指msg赋值给第一个问号
本文链接:http://www.yayihouse.com/yayishuwu/chapter/1577