java.sql.SQLException: 参数1没有指定数值

huangapple 未分类评论49阅读模式
英文:

java.sql.SQLException:No value specifies for paramerter 1

问题

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/CSMS2", "root", "");
        String sql = "Select * from student_status where semester=?";
        String sql1 = "Select count(*) from student_status";
        String sql2 = "Select * from stocks where sno=1";
        String sql3 = "Update stocks set RS=?, BS=?, GS=?, Files=?, EDS=? where sno =1";
        PreparedStatement pst = con.prepareStatement(sql);
        PreparedStatement pst1 = con.prepareStatement(sql1);
        PreparedStatement pst2 = con.prepareStatement(sql2);
        PreparedStatement pst3 = con.prepareStatement(sql3);
        ResultSet rs = pst.executeQuery();
        ResultSet rs1 = pst1.executeQuery();
        ResultSet rs2 = pst2.executeQuery();
        int sno=1, SRS=0, SBS=0, SGS=0, SFiles=0, SEDS=0;
        if (rs.next() && rs1.next() && rs2.next()) {
            int count = rs.getInt(1);
            while (sno <= count) {
                int x = rs.getInt("semester");
                if (x == 1) {
                    int RS = 5, BS = 1, GS = 1, Files = 6, EDS = 0;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                if (x == 2) {
                    int RS = 5, BS = 1, GS = 1, Files = 6, EDS = 10;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                if (x == 3) {
                    int RS = 5, BS = 1, GS = 1, Files = 6, EDS = 0;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                if (x == 4) {
                    int RS = 6, BS = 1, GS = 1, Files = 6, EDS = 0;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                if (x == 5) {
                    int RS = 5, BS = 1, GS = 1, Files = 6, EDS = 0;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                if (x == 6) {
                    int RS = 6, BS = 1, GS = 1, Files = 6, EDS = 0;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                if (x == 7) {
                    int RS = 5, BS = 1, GS = 1, Files = 6, EDS = 0;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                if (x == 8) {
                    int RS = 4, BS = 1, GS = 1, Files = 5, EDS = 0;
                    SRS = SRS + RS; SBS = SBS + BS; SGS = SGS + GS; SFiles = SFiles + Files; SEDS = SEDS + EDS;
                }
                sno++;
            }
            int RSDB = rs2.getInt("RS");
            int BSDB = rs2.getInt("BS");
            int GSDB = rs2.getInt("GS");
            int FilesDB = rs2.getInt("Files");
            int EDSDB = rs2.getInt("EDS");

            int RSUDB = RSDB - SRS;
            int BSUDB = BSDB - SBS;
            int GSUDB = GSDB - SGS;
            int FilesUDB = FilesDB - SFiles;
            int EDSUDB = EDSDB - SEDS;

            pst3.setInt(1, RSUDB);
            pst3.setInt(2, BSUDB);
            pst3.setInt(3, GSUDB);
            pst3.setInt(4, FilesUDB);
            pst3.setInt(5, EDSUDB);

            pst3.executeUpdate();
        }

        con.close();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "invalid");
    }
}
英文:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
         try{
            Class.forName(&quot;com.mysql.jdbc.Driver&quot;);
            Connection con = DriverManager.getConnection(&quot;jdbc:mysql://localhost:3306/CSMS2&quot;,&quot;root&quot;,&quot;&quot;);
            String sql = &quot;Select * from student_status where semester=?&quot;;
            String sql1 = &quot;Select count(*) from student_status&quot;;
            String sql2 = &quot;Select * from stocks where sno=1&quot;;
            String sql3 = &quot;Update stocks set RS=? ,BS=? ,GS=? ,Files=? ,EDS=? where sno =1&quot;;
            PreparedStatement pst = con.prepareStatement(sql);
            PreparedStatement pst1 = con.prepareStatement(sql1);
            PreparedStatement pst2 = con.prepareStatement(sql2);
            PreparedStatement pst3 = con.prepareStatement(sql3);
            ResultSet rs = pst.executeQuery();
            ResultSet rs1 = pst1.executeQuery();
            ResultSet rs2 = pst2.executeQuery();
            int sno=1,SRS=0,SBS=0,SGS=0,SFiles=0,SEDS=0;
           if(rs.next() &amp;&amp; rs1.next()&amp;&amp; rs2.next())
           {
             int count= rs.getInt(1);
             while(sno &lt;=count)
             {
                int x= rs.getInt(&quot;semester&quot;);
                if (x ==1)
                {
                   int RS = 5,BS=1,GS=1,Files=6,EDS=0;  
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files; SEDS= SEDS+EDS;
                }
                if (x ==2)
                {
                   int RS = 5,BS=1,GS=1,Files=6,EDS=10;   
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files; SEDS= SEDS+EDS;
                }
                if (x ==3)
                {
                   int RS = 5,BS=1,GS=1,Files=6,EDS=0;
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files ;SEDS= SEDS+EDS;
                }
                if (x ==4)
                {
                   int RS = 6,BS=1,GS=1,Files=6,EDS=0;
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files; SEDS= SEDS+EDS;
                }
                if (x ==5)
                {
                   int RS = 5,BS=1,GS=1,Files=6,EDS=0;
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files; SEDS= SEDS+EDS;
                }
                if (x ==6)
                {
                   int RS = 6,BS=1,GS=1,Files=6,EDS=0; 
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files; SEDS= SEDS+EDS;
                }
                if (x ==7)
                {
                   int RS = 5,BS=1,GS=1,Files=6,EDS=0; 
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files; SEDS= SEDS+EDS;
                }
                if(x ==8)
                {
                   int RS = 4,BS=1,GS=1,Files=5,EDS=0;   
                   SRS= SRS+RS; SBS= SBS+BS; SGS= SGS+GS; SFiles= SFiles+Files; SEDS= SEDS+EDS;
                }
              sno++;
             }
                int RSDB= rs2.getInt(&quot;RS&quot;);
                int BSDB= rs2.getInt(&quot;BS&quot;);
                int GSDB= rs2.getInt(&quot;GS&quot;);
                int FilesDB= rs2.getInt(&quot;Files&quot;);
                int EDSDB= rs2.getInt(&quot;EDS&quot;);
                
                int RSUDB= RSDB-SRS;
                int BSUDB= BSDB-SBS;
                int GSUDB= GSDB-SGS;
                int FilesUDB= FilesDB-SFiles;
                int EDSUDB= EDSDB-SEDS;
               // pst3.setInt(1,0);
                pst3.setInt(1,RSUDB);
                pst3.setInt(2,BSUDB);
                pst3.setInt(3,GSUDB);
                pst3.setInt(4,FilesUDB);
                pst3.setInt(5,EDSUDB);
                
                pst3.executeUpdate();     
              
         }
        
          con.close();
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null,&quot;invalid&quot;);
        }
    }

huangapple
  • 本文由 发表于 2020年5月19日 19:33:40
  • 转载请务必保留本文链接:https://java.coder-hub.com/61890034.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定