您的位置:首页技术文章
文章详情页

jdbc - 关于错误:java.sql.SQLException: 未调用 ResultSet.next的问题

【字号: 日期:2023-10-23 09:49:27浏览:30作者:猪猪

问题描述

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));}

标签: java
相关文章: