日期:2014-05-17  浏览次数:20742 次

mysql Statement parameter 1 not set.
代码:提示的错误在rs = pstm.executeQuery();
public List<Type> queryTAll() throws Exception {
  DBConnection dbc = new DBConnection();
  List<Type> list = new ArrayList<Type>();
  sql = "select * from type where id=?";
  ResultSet rs = null;
  try {
  pstm = dbc.getConnection().prepareStatement(sql);
  rs = pstm.executeQuery();
  while (rs.next()) {
  Type type = new Type();
  type.setId(rs.getInt(1));
  type.setNtype1(rs.getInt(2));
  type.setNtype2(rs.getInt(3));
  type.setNtype1name(rs.getString(4));
  type.setNtype2name(rs.getString(5));
  list.add(type);
  }
  } catch (Exception e) {
  e.printStackTrace();
  } 
  return list;
  }
mysql数据库,另外type表中有(id、ntype1、ntype2、ntype1name、ntype2name)五列,前三列为int,后面为varchar
错误如下:
java.sql.SQLException: Statement parameter 1 not set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1045)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:693)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)


这错误在百度上都说是参数设置有问题,但我检查了参数并没问题,请大家帮忙解决下,谢谢啦!

------解决方案--------------------
很明显啊select * from type where id=?你的?没有赋值