suchen

Heim  >  Fragen und Antworten  >  Hauptteil

jdbc – Über den Fehler: java.sql.SQLException: ResultSet.next nicht aufgerufen

1.` public Res evaluierenCourse(@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. Testcode:

    void testEvaluateCourse() {
        CourseEvaluateServiceImpl ce = new CourseEvaluateServiceImpl();
        String str = "15,15,10,0,0,0";
        ce.evaluateCourse(1,str.toString());
    }

3. Fehlermeldung:

开始尝试连接数据库!
连接成功
TEACHPROGRAM = 15

java.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.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)

Nach dem Aufruf von ResultSet.next() bewegt sich der Cursor in die nächste Zeile. Wie wäre es, wenn Sie ihn mehrmals auf diese Weise aufrufen?
Ich habe wirklich viele Informationen überprüft. Ich hoffe, dass Gott gnädig ist. Ich bin wirklich nur ein Anfänger mit einem sehr schwachen Verständnis.
Wenn ich wirklich Informationen zur Lösung des Problems finden könnte, würde ich nicht hierher kommen, um danach zu fragen! ! ! !

黄舟黄舟2731 Tage vor865

Antworte allen(1)Ich werde antworten

  • 扔个三星炸死你

    扔个三星炸死你2017-06-28 09:26:44

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

    Antwort
    0
  • StornierenAntwort