一个添加页面提交后出现这样的错误,而且添加失败 请问是什么原因?怎么解决?先谢谢大家~java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.preImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.preImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
参数绑定不对嘛
看看setXXX是否匹配
第一个id是数据库自己加1的标识
那我写insert into hotel values(?,?,?...)
PreparedStatement ps ....
ps.setString(1,hotel.getH_id)?
还是应该写
ps.setString(2,hotel.getH_id)?
还有括号里边应该有几个问号啊?
还有插入操作最好字段都写出来!
int row = -1;
String sql = "insert into hotel values (?,?,?,?,?,?,?,?,?,?,?)";
Connection conn = null;
PreparedStatement ps = null;
BaseDAO bd = new BaseDAO();
conn = bd.getConn();
try {
ps = conn.prepareStatement(sql);
ps.setString(2, hotel.getH_id());
ps.setString(3, hotel.getH_name());
ps.setString(4, (hotel.getH_level()));
ps.setString(5, hotel.getH_tel());
ps.setString(6, hotel.getH_fax());
ps.setString(7, hotel.getH_address());
ps.setString(8, hotel.getH_link());
ps.setString(9, hotel.getH_time());
ps.setString(10, hotel.getH_re());
ps.setString(11,hotel.getH_pay());
row = ps.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
}
bd.closePrepStmt(ps);
bd.closeConnection(conn);
return row;
}
下边那个 ps.setString(2, hotel.getH_id());是这样写对还是应该写成
ps.setString(1, hotel.getH_id());