help me!!
我对一张表尽心插入操作,然后,去取系统生成的id ,出现如下错误
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:526)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:467)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1422)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:523)
我得数据库操作如下
public String getStaffId(SignupForm form) throws Exception{
Connection con = CreateConnection.getConnection();
Statement smt = con.createStatement();
String COURSE_SYS_ID=Until.toGBK(form.getCOURSE_SYS_ID()) ;
String COURSE_CODE=Until.toGBK(form.getCOURSE_CODE());
String SIGN_DATE=form.getSIGN_DATE() ;
String Name=Until.toGBK(form.getName()) ;
String ID_CODE=Until.toGBK(form.getID_CODE() );
String PHONE=Until.toGBK(form.getPHONE()) ;
String BIRTH_DATE=Until.toGBK(form.getBIRTH_DATE());
String EMAIL=Until.toGBK(form.getEMAIL() );
String DIPLOMA=Until.toGBK(form.getDIPLOMA() );
String SPECIALTY=Until.toGBK(form.getSPECIALTY() );
String UNIT_ADDR=Until.toGBK(form.getUNIT_ADDR() );
String POST_CODE=Until.toGBK(form.getPOST_CODE() );
String JOB_RESUME=Until.toGBK(form.getJOB_RESUME() );
String SEX=Until.toGBK(form.getSEX() );
String EXER_STAFF_NAME=Until.toGBK(form.getEXER_STAFF_NAME() );
String RETAIN_UNIT_SYS_ID=Until.toGBK(form.getRETAIN_UNIT_SYS_ID());
String sql="select * from T_EXERCISE_STAFF where ID_CODE="+ID_CODE;
String sql1="insert into T_EXERCISE_STAFF (EXER_STAFF_NAME,ID_CODE,PHONE,EMAIL,DIPLOMA,SPECIALTY,POST_CODE,JOB_RESUME,SEX,RETAIN_UNIT_SYS_ID) values('"
+EXER_STAFF_NAME+"',"+
"'"+ID_CODE+"',"
+"'"+PHONE+"',"
+"'"+EMAIL+"',"
+"'"+DIPLOMA+"',"
+"'"+SPECIALTY+"',"
+"'"+POST_CODE+"',"
+"'"+JOB_RESUME+"',"
+"'"+SEX+"',"
+"'"+RETAIN_UNIT_SYS_ID+"')";
ResultSet rs=smt.executeQuery(sql) ;
if(rs.next() ){
String id=rs.getString(1);
System.out .println("system already exist the staff!!");
return id;
}
else{
System.out .println("insert record=========="+sql1);
smt.execute(sql1);
// con.commit();
rs=smt.executeQuery(sql);
String id=rs.getString(1);
con.close() ;
return id;
}
}