Hi, i geth an erros on my sql querry, but I'm not sure why the error is:
Column count doesn't match value count at row 1
The error is on the line:
stmt.executeQuerry(sql1)
so I assumed that there is an error in the sql1 querry.
If I interpret it the right way it means that I specify too less or too much columns compare to the number of values I try to enter, but I counted and recounted them and it seems to be ok. Here is the code (the query is the string sql):
String[] array = value.split("=");
int credit = array.length-1;
java.sql.Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException e1) {
e1.printStackTrace();
}
String sql = ("INSERT INTO std_details (StudentID, LastName, FirstName,"+
"Initial, City, State,"+
"Phone, Gender, Year,"+
"Major, Credits, CGPA)"+
"VALUES('"
+ array[1] + "','"
+ array[5] + "','"
+ array[4] + "','"
+ array[2] + "','"
+ array[7] + "','"
+ array[8] + "','"
+ array[6] + "','"
+ array[3] + "','"
+ array[array.length-3] + "','"
+ array[array.length-1] + "','"
+ array[array.length-2] + "','"
+ array[array.length-4] + "');");
String sql1 = ("INSERT INTO csr_courses (StudentID"+
", Course_1, Grade_1, CourseCredit_1"+
", Course_2, Grade_2, CourseCredit_2"+
", Course_3, Grade_3, CourseCredit_3"+
", Course_4, Grade_4, CourseCredit_4"+
", Course_5, Grade_5, CourseCredit_5) "
+"VALUES('"
+ array[1] + "','"
+ array[9] + "','"
+ array[10] + "','"
+ array[11] + "','"
+ array[12] + "','"
+ array[13] + "','"
+ array[14] + "','"
+ array[15] + "','"
+ array[16] + "','"
+ array[17] + "','"
+ array[18] + "','"
+ array[19] + "','"
+ array[20] + "','"
+ array[21] + "','"
+ array[22] + "');");
if (duplicate(array[1].toString())){
try {
System.out.println("found ducplicate");
os.writeObject("AddSudent duplicate");
os.flush();
os.reset();
} catch (IOException e) {
e.printStackTrace();
}
}else{
try {
stmt.executeUpdate(sql);
stmt.executeUpdate(sql1);
stmt.close();
os.writeObject("AddSudent ok");
os.flush();
os.reset();
} catch (SQLException | IOException e1) {
e1.printStackTrace();
try {
os.writeObject("AddSudent fail");
os.flush();
os.reset();
} catch (IOException e) {
e.printStackTrace();
}
}
}