jdbc - 关于错误:java.sql.SQLException: 未调用 ResultSet.next的问题
问题描述
1.`public Res evaluateCourse(@FormParam('stuId') int stuId, @FormParam('score') String score) {
Res res = new Res();Connection con = null;ResultSet rs = null;String[] temp = score.split(',');int count = 0;try{ con = getConnection(); Statement sm = con.createStatement(); String selectStuId = 'select evaluateId from evaluate where stuId = ' + stuId; rs = sm.executeQuery(selectStuId); for(String s: temp) {int scoreInt = Integer.parseInt(s);count++;switch (count) { case 1:int TEACHPROGRAM = scoreInt;System.out.println('TEACHPROGRAM = ' + TEACHPROGRAM);String insert1 = 'insert into evaluateDesc(EVALUATEID,ATTRNAME,ATTRSCORE) values(' + rs.getInt('evaluateId')+ ',' + TEACHPROGRAM + ')';System.out.println(insert1);rs = sm.executeQuery(insert1);if(rs.next()){ System.out.println('TEACHPROGRAM = ' + rs.getInt(TEACHPROGRAM));}continue; case 2:int LECTURECONTENT = scoreInt;System.out.println('LECTURECONTENT = ' + LECTURECONTENT);String insert2 = 'insert into evaluateDesc(evaluateId,attrName,attrScore) values (' + rs.getInt('evaluate')+ ',' + LECTURECONTENT + ')';rs = sm.executeQuery(insert2);if(rs.next()){ System.out.println('LECTURECONTENT = ' + rs.getInt(LECTURECONTENT));}continue; case 3:int LECTUREMETHOD = scoreInt;System.out.println('LECTUREMETHOD = ' + LECTUREMETHOD);String insert3 = 'insert into evaluateDesc(evaluateId,attrName,attrScore) values (' + rs.getInt('evaluate')+ ',' + LECTUREMETHOD + ')';rs = sm.executeQuery(insert3);if(rs.next()){ System.out.println('LECTUREMETHOD = ' + rs.getInt(LECTUREMETHOD));}continue; case 4:int TSINTERACTION = scoreInt;System.out.println('TSINTERACTION = ' + TSINTERACTION);String insert4 = 'insert into evaluateDesc(evaluateId,attrName,attrScore) values (' + rs.getInt('evaluate')+ ',' + TSINTERACTION + ')';rs = sm.executeQuery(insert4);if(rs.next()){ System.out.println('TSINTERACTION = ' + rs.getInt(TSINTERACTION));}continue; case 5:int EVAMETHOD = scoreInt;System.out.println('EVAMETHOD = ' + EVAMETHOD);String insert5 = 'insert into evaluateDesc(evaluateId,attrName,attrScore) values (' + rs.getInt('evaluate')+ ',' + EVAMETHOD + ')';rs = sm.executeQuery(insert5);if(rs.next()){ System.out.println('EVAMETHOD = ' + rs.getInt(EVAMETHOD));}continue; case 6:int EVALUATE = scoreInt;System.out.println('EVALUATE = ' + EVALUATE);String insert6 = 'insert into evaluateDesc(evaluateId,attrName,attrScore) values (' + rs.getInt('evaluate')+ ',' + EVALUATE + ')';rs = sm.executeQuery(insert6);if(rs.next()){ System.out.println('EVALUATE = ' + rs.getInt(EVALUATE));}break;} }}catch (Exception e){ e.printStackTrace();}res.setMsg('评教成功');return res; } `
2.测试代码:
void testEvaluateCourse() {CourseEvaluateServiceImpl ce = new CourseEvaluateServiceImpl();String str = '15,15,10,0,0,0';ce.evaluateCourse(1,str.toString()); }
3.错误信息:
开始尝试连接数据库!连接成功TEACHPROGRAM = 15java.sql.SQLException: 未调用 ResultSet.next at oracle.jdbc.driver.GeneratedScrollableResultSet.getInt(GeneratedScrollableResultSet.java:565) at oracle.jdbc.driver.GeneratedResultSet.getInt(GeneratedResultSet.java:1350) at serviceImpl.CourseEvaluateServiceImpl.evaluateCourse(CourseEvaluateServiceImpl.java:45) at service.CourseEvaluateService$evaluateCourse.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at serviceImpl.CourseEvaluateServiceImplTest.testEvaluateCourse(CourseEvaluateServiceImplTest.groovy:10) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.textui.TestRunner.doRun(TestRunner.java:116) at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:113) at junit.textui.TestRunner.doRun(TestRunner.java:109) at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:45) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
调用ResultSet.next()之后光标移动到下一行,那么像这样多次调用呢?我真的查了很多资料了,希望大神手下留情,我真的只是个理解能力特别薄弱的小白,别举报了。如果我真的能查到资料解决问题,我是不会来这里问的!!!!
问题解答
回答1:以Case 1 为例
rs = sm.executeQuery(selectStuId);//执行下面的rs.getInt('evaluateId'),之前没有调用过next,会出错String insert1 = 'insert into evaluateDesc(EVALUATEID,ATTRNAME,ATTRSCORE) values(' + rs.getInt('evaluateId')+ ',' + TEACHPROGRAM + ')';rs = sm.executeQuery(insert1);//这是对的if(rs.next()){ System.out.println('TEACHPROGRAM = ' + rs.getInt(TEACHPROGRAM));}
相关文章:
1. javascript - 引入 simditor,但是显示标签,这个怎么解决。2. docker api 开发的端口怎么获取?3. android - 目前有哪些用Vue.js开发移动App的方案?4. Android PopupWindow 问题。5. calss调用了 也设置了颜色,可是网站不显示。请问大佬是什么情况啊6. cas项目起个名字7. python - scrapy获取网页指定内容,后翻到下一页继续,固定循环次数。。问题8. angular.js - angular route如何实现单页面切换时数据的传递9. background属性顺序?10. centos6.5 安装kvm