错误:
com.microsoft.sqlserver.jdbc.SQLServerException: 索引 1 超出范围。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setString(Unknown Source)
at Model.GoodsBeanBo.getGoodsBeans(GoodsBeanBo.java:19)
at Servlet.ShowGoods.doGet(ShowGoods.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
代码:private Connection ct = null;
private PreparedStatement ps = null;
private ResultSet rs = null;
GoodsBeans gb = new GoodsBeans();
public GoodsBeans getGoodsBeans(String goodsId) {
// 根据ID,取得信息
GoodsBeans gb = new GoodsBeans();
try {
ct = new ConnDB().getConnection();
ps = ct.prepareStatement("select * from goods where goodsId=''");
ps.setString(1, goodsId);
rs = ps.executeQuery();
if (rs.next()) {
gb.setGoodsId(rs.getInt(1));
gb.setGoodsName(rs.getString(2));
gb.setGoodsIntro(rs.getString(3));
gb.setGoodsPrice(rs.getFloat(4));
gb.setGoodsNum(rs.getInt(5));
gb.setGoodsProd(rs.getString(6));
gb.setGoodsPhoto(rs.getString(7));
gb.setGoodsType(rs.getString(8));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
this.close();
}
return gb;
}
------解决方案--------------------
select * from goods
你这个表的 字段数和底下赋值的数不一样。
你对比下把。建议 把* 改成字段名。
------解决方案--------------------
先去检查下表结构,应该和你下面获取不匹配
------解决方案--------------------
ps.setString(1, goodsId);为字符串,
而数据表的goodsId为int,这样没有问题吗?
------解决方案--------------------
改成int试下先