日期:2014-05-18  浏览次数:21437 次

mysql出现No value specified for parameter1?
就是在jsp中页面中把从上个页面获得的数据写入mysql数据库,数据能写入数据库,但tomcat却给出错误信息:No value specified for parameter1。有哪位高手遇见过,给解释下,最好给出解决方法,谢谢啦。我的代码如下:
  String ac = request.getParameter("account");
  String pa = request.getParameter("password");
  int dataID=0;
  boolean regstate=false;
  Connection conn = null;
  PreparedStatement ps = null;
  try {
  Class.forName("com.mysql.jdbc.Driver");
  String url = "jdbc:mysql://localhost/userdata?user=root&password=429300";
  conn = DriverManager.getConnection(url);
  String sqlString = "insert into users (id,account,password) values (?,?,?)";
  ps = conn.prepareStatement(sqlString);
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery("select * from chart"); 
while(rs.next()){dataID++;}
out.println(dataID);
  stmt.executeUpdate("insert into chart values('"+(dataID+1)+"','"+ac+"',"+pa+");"); 
  if (ps.executeUpdate() > 0)
  regstate=true;

  } catch (Exception e) {
  // TODO: handle exception
  System.out.println("插入失败");
  e.printStackTrace();
  } finally {
  try {
  if (ps != null) {
  ps.close();
  ps = null;
  }
  if (conn != null) {
  conn.close();
  conn = null;
  }
  } catch (Exception e2) {
  e2.printStackTrace();
  // TODO: handle exception
  }
  }

------解决方案--------------------
数据库表未与程序对应,仔细检查。
------解决方案--------------------
String sqlString = "insert into users (id,account,password) values (?,?,?)";
ps = conn.prepareStatement(sqlString);
Statement stmt = conn.createStatement();


把问号里的值设置进去
利用ps.setString(1,"");等
------解决方案--------------------
探讨
对应了啊,哪儿没对应啊?