英文:
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("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,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,"invalid");
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论