关于java向mysql插入数据时出现的问题 10
我在用java向mysql插入数据时后台总是报出错误,ThuMar2615:39:38CST2009WARN:Invalidvalue{1}forservervariab...
我在用java向mysql插入数据时后台总是报出错误,Thu Mar 26 15:39:38 CST 2009 WARN: Invalid value {1} for server variable named {0}, falling back to sane default of {2}.我不知道这个是什么意思,大家能否告诉一下怎样解决呢~~数据能够成功提交,但是就是在java的其他方面老是出错,比如在捕获自定义的异常的时候会把异常全都给捕获,谢谢大家告诉我一下哦
DB db = new DB();
String sql = "insert into user values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,now(),?,?,?,?,?)";
Connection conn = db.getConn();
PreparedStatement pstmt = db.createPreparedStatement(conn, sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
pstmt.setString(3, email);
pstmt.setString(4, question);
pstmt.setString(5, answer);
pstmt.setString(6, sex);
pstmt.setString(7, telphone);
pstmt.setString(8, birthday);
pstmt.setString(9, job);
pstmt.setString(10, headimage);
pstmt.setString(11, city);
pstmt.setString(12, qq);
pstmt.setString(13, msn);
pstmt.setString(14, usernet);
pstmt.setInt(15, level);
pstmt.setInt(16, experience);
pstmt.setInt(17, jinghua);
pstmt.setInt(18, weiwang);
pstmt.setInt(19, posts);
pstmt.setInt(20, meili);
pstmt.executeUpdate();
db.close(pstmt);
db.close(conn);
// TODO Auto-generated method stub
return mapping.findForward("success");
}
} 展开
DB db = new DB();
String sql = "insert into user values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,now(),?,?,?,?,?)";
Connection conn = db.getConn();
PreparedStatement pstmt = db.createPreparedStatement(conn, sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
pstmt.setString(3, email);
pstmt.setString(4, question);
pstmt.setString(5, answer);
pstmt.setString(6, sex);
pstmt.setString(7, telphone);
pstmt.setString(8, birthday);
pstmt.setString(9, job);
pstmt.setString(10, headimage);
pstmt.setString(11, city);
pstmt.setString(12, qq);
pstmt.setString(13, msn);
pstmt.setString(14, usernet);
pstmt.setInt(15, level);
pstmt.setInt(16, experience);
pstmt.setInt(17, jinghua);
pstmt.setInt(18, weiwang);
pstmt.setInt(19, posts);
pstmt.setInt(20, meili);
pstmt.executeUpdate();
db.close(pstmt);
db.close(conn);
// TODO Auto-generated method stub
return mapping.findForward("success");
}
} 展开
展开全部
第一个设为null是错的,应该取消,这是自动生成的ID。
应该这样
String sql = "insert into user values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,now(),?,?,?,?,?)";
Connection conn = db.getConn();
PreparedStatement pstmt = db.createPreparedStatement(conn, sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
pstmt.setString(3, email);
pstmt.setString(4, question);
pstmt.setString(5, answer);
pstmt.setString(6, sex);
pstmt.setString(7, telphone);
pstmt.setString(8, birthday);
pstmt.setString(9, job);
pstmt.setString(10, headimage);
pstmt.setString(11, city);
pstmt.setString(12, qq);
pstmt.setString(13, msn);
pstmt.setString(14, usernet);
pstmt.setInt(15, level);
pstmt.setInt(16, experience);
pstmt.setInt(17, jinghua);
pstmt.setInt(18, weiwang);
pstmt.setInt(19, posts);
pstmt.setInt(20, meili);
pstmt.executeUpdate();
同时,数据库中id应该设为auto_increment primary key
应该这样
String sql = "insert into user values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,now(),?,?,?,?,?)";
Connection conn = db.getConn();
PreparedStatement pstmt = db.createPreparedStatement(conn, sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
pstmt.setString(3, email);
pstmt.setString(4, question);
pstmt.setString(5, answer);
pstmt.setString(6, sex);
pstmt.setString(7, telphone);
pstmt.setString(8, birthday);
pstmt.setString(9, job);
pstmt.setString(10, headimage);
pstmt.setString(11, city);
pstmt.setString(12, qq);
pstmt.setString(13, msn);
pstmt.setString(14, usernet);
pstmt.setInt(15, level);
pstmt.setInt(16, experience);
pstmt.setInt(17, jinghua);
pstmt.setInt(18, weiwang);
pstmt.setInt(19, posts);
pstmt.setInt(20, meili);
pstmt.executeUpdate();
同时,数据库中id应该设为auto_increment primary key
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询