java.sql.SQLException:列计数与第 1 行的值计数不匹配,我的数据库的第一列是自动加密的



我正试图在数据库中插入值,这样,如果用户选择标记为基数,则标记将被保存,而如果用户选择等级基数标记feild为空,则应存储等级。我的主键是gid,它是自动递增的,sid是此处的forign键。如果有人能帮助我,我将无法获取并解决此错误。

private void hide1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
regstration r=new regstration();
Daoregistration dao=new Daoregistration();
if(mark1.getText().length()<0)
{
r.marks=Integer.parseInt(mark1.getText());
}
r.ch=Integer.parseInt(jComboBox2. getSelectedItem().toString());
r.semister=jComboBox1.getSelectedItem().toString();
r.subject1=subj1.getText();
if(jRadioButton2.isSelected()){
r.grade1=(String)jComboBox3.getSelectedItem();

}
int a =dao.gpa(r);
System.out.print(a);
try{
String qry="select * from formula where grades=? or percentage=?";

PreparedStatement pst=dao.con.prepareStatement(qry);
pst.setInt(1, Integer.parseInt(mark1.getText()));
pst.setString(2,(String)jComboBox3.getSelectedItem());
ResultSet rs=pst.executeQuery();
if(rs.next())
{
r.gpoint=rs.getFloat("grade points");
}


}
catch(Exception ex){
}
subj1.setVisible(false);
mark1.setVisible(false);

jComboBox2.setVisible(false);
jComboBox3.setVisible(false);
}                                     

private void hide2ActionPerformed(java.awt.event.ActionEvent evt) {                                      
subj2.setVisible(false);
mark2.setVisible(false);

jComboBox4.setVisible(false);
jComboBox10.setVisible(false);
}                                     

private void jComboBox5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
// TODO add your handling code here:
}                                          

private void hide3ActionPerformed(java.awt.event.ActionEvent evt) {                                      
subj3.setVisible(false);
mark3.setVisible(false);

jComboBox5.setVisible(false);
jComboBox11.setVisible(false);
}                                     

private void hide4ActionPerformed(java.awt.event.ActionEvent evt) {                                      
subj4.setVisible(false);
mark4.setVisible(false);

jComboBox6.setVisible(false);
jComboBox12.setVisible(false);
} 

我的gpa模块代码是

int gpa(regstration r)
{
int res=0;
try{
connection();
String qry="insert into gpa values(?,?,?,?,?,?,?)";
PreparedStatement pst=con.prepareStatement(qry);
pst.setInt(1, r.sid);
pst.setString(2,r.semister);
pst.setString(3,r.subject1);

pst.setInt(4,r.marks);

pst.setString(5,r.grade1);
pst.setInt(6,r.ch);
pst.setFloat(7,r.gpoint);



res=pst.executeUpdate();

}
catch(Exception e)
{
System.out.println(e.toString());
}
return res;
}
}                            

指定插入语句中的列

String qry="insert into gpa (col1, ... , col7) values(?,?,?,?,?,?,?)";

列数必须与问号数相匹配。

最新更新