posted 9 years ago
I am having trouble getting this update statement to work:
****
@Override
public void update(){
Statement stmt;
try{
ConnectIt conn = new ConnectIt();
stmt=conn.makeStatement();
String thesisTitle;
String thesisAdvisor;
String company;
Scanner in = new Scanner(System.in);
System.out.println("Update the record");
System.out.println("Please enter the Student ID for the record you want to update >");
studentID = Integer.parseInt(in.next());
System.out.println("Please enter the new GPA>");
gpa = in.nextFloat();
System.out.println("Please enter new status, must be resident or nonresident>");
status = in.next();
System.out.println("Please enter new mentor");
mentor = in.next();
System.out.println("Enter new level, must be freshman, sophmore, junior, or senior>");
level = in.next();
thesisTitle = "n/a";
thesisAdvisor = "n/a";
company = "n/a";
// stmt.executeUpdate("Update student Set firstName='" + firstName + "', lastName='" + lastName + "', gpa='" + gpa + "', status='" + status + "', mentor='" + mentor + "', level='" + level + "' + thesisTitle ='" + thesisTitle + "' + thesisAdvisor ='" + thesisAdvisor + "' WHERE studentID=
//'" + studentID + "'");
stmt.executeUpdate("Update student Set firstName='" + firstName + "', lastName='" + lastName + "', gpa='" + gpa + "', status='" + status + "', mentor='" + mentor + "', level='" + level + "', + thesisTitle ='" + thesisTitle + "', + thesisAdvisor ='" + thesisAdvisor + "' WHERE studentID=
'" + studentID + "'");
stmt.close();
conn.close();
}
catch (SQLException e){
System.err.println("ERROR: Either cannot connect to db" + " or error with SQL statement.");
}
System.out.println("Undergraduate Student record successfully updated");
}
******
the result is that it gives me the SQLException message and the sucess message but does not update the database