`
twentygjh
  • 浏览: 15982 次
  • 性别: Icon_minigender_1
  • 来自: 常德
文章分类
社区版块
存档分类
最新评论

java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 1

阅读更多
        java.sql.SQLException: 索引中丢失  IN 或 OUT 参数:: 1

代码如下:
public static void deleteEmpInfo(int empno){
StringBuffer sqlStr = new StringBuffer("delete from emp where empno = ? ");
try{
conn = DBconn.getConn();
pstmt = conn.prepareStatement(sqlStr.toString());
int t = pstmt.executeUpdate();
if(t != 0){
System.out.println("删除成功!");
}else{
System.out.println("删除失败!");
}
}catch(Exception e){
e.printStackTrace();
}
}

调试出现如下错误:
java.sql.SQLException: 索引中丢失  IN 或 OUT 参数:: 1
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1738)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3382)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3468)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at com.ibm.project.dao.GetEmpInfo.deleteEmpInfo(GetEmpInfo.java:96)
at com.ibm.project.dao.GetEmpInfo.main(GetEmpInfo.java:108)


解决方法:在pstmt = conn.prepareStatement(sqlStr.toString());和
int t = pstmt.executeUpdate();之间需加一条语句pstmt.setInt(1,empno);

    调用deleteEmpInfo(8005)方法时,将实参传给形参。执行pstmt.setInt(1,empno)语句时,也就是说必须先将索引1处的值设置为empno即8005,再执行删除操作,才能操作成功。
分享到:
评论
1 楼 binjoo 2011-06-22  
aa
bbccaabbccaabbccaabbccaabbcc

相关推荐

Global site tag (gtag.js) - Google Analytics