不显示删除回复显示所有回复显示星级回复显示得分回复 com.microsoft.sqlserver.jdbc.SQLServerException: 索引 1

woxiuqiaokeli 2010-01-03 12:06:15
各位大侠 帮帮忙吧 实在不知哪出错了
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 cn.com.chengang.swt.Book$10.delt(Book.java:391)
at cn.com.chengang.swt.Book$10.widgetSelected(Book.java:372)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
at cn.com.chengang.swt.Book.main(Book.java:461)
索引 1 超出范围。

我的程序:
// 加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=library";
// 连接服务器和数据库library
String userName = "sa"; //默认用户名
String userPwd = "123"; //密码
Connection dbConn = null;
PreparedStatement stmt=null;
String BookNOTexts=BookNOText.getText().trim();

try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
stmt=dbConn.prepareStatement("delete from Book where BookNO=?");
stmt.setString(1,BookNOTexts);
stmt.executeUpdate();
int res=stmt.executeUpdate();
} catch (ClassNotFoundException a) {
System.out.println(a.getMessage());
} catch (SQLException edd) {
edd.printStackTrace();
System.out.println(edd.getMessage());
} finally{
try {
stmt.close();
dbConn.close();
} catch (SQLException a) {
// e.printStackTrace();
}
}
...全文
53 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
woxiuqiaokeli 2010-01-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hyowner 的回复:]
stmt.setString(1,BookNOTexts);换成stmt.setString(0,BookNOTexts);应该就这的问题了
[/Quote]
它应该是0 sql server
谢谢啦 我那问号写成英文的就好了
woxiuqiaokeli 2010-01-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 baiyu123 的回复:]
stmt.executeUpdate();
int res=stmt.executeUpdate();
可能是执行了2次
[/Quote]
谢谢啦 我那问号写成英文的就好了
hyowner 2010-01-03
  • 打赏
  • 举报
回复
stmt.setString(1,BookNOTexts);换成stmt.setString(0,BookNOTexts);应该就这的问题了
学习Java中 2010-01-03
  • 打赏
  • 举报
回复
stmt.executeUpdate();
int res=stmt.executeUpdate();
可能是执行了2次

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧