java数据库操作代码
执行这段代码显示更新失败,有语法错误,请大家给看看
//发送消息并写入数据库 public static void putMessage(int from, int to, byte[] data, int flag, long time) throws SQLException { OperateData db = new OperateData(); String message = new String(data); //String TIME =""+time; String sql = "insert into mess(id1,id2,flag,mess,time) values ('"+from+"','"+to+"','"+flag+"','"+message+",'"+time+"')"; db.executeUpdate(sql); db.closed(); }
String sql = "insert into mess(id1,id2,flag,mess,time) values ('"+from+"','"+to+"','"+flag+"','"+message+"','"+time+"')";
[解决办法]
1楼正解,建议使用PreparedStatement,因为你那种写法容易出错,而且容易遭受sql注入