Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:59:10+00:00 2026-06-14T11:59:10+00:00

I have two issues, but I am only working on correcting one currently. In

  • 0

I have two issues, but I am only working on correcting one currently. In my program on line 331, when I execute it I get the error (catch statement) that there is an error with the SQL statement. It is identical to the others (that I see) and I am not seeing the error. Here is a snippet of the section that gives an error. I should just be able to update mysql database, just as the other sections do, this one errors. Where should I look? Something did not post correctly, I am looking at that too, sorry.

    //String st = "DELETE FROM student WHERE Description = 'Michael'";
    // String st = “UPDATE student SET Description = + ‘Michael’ WHERE studentID = ‘123’”;
    String studentID;
    String firstName;
    String lastName;
    double gpa;
    String status;
    String mentor;
    String level;
    String thesisTitle;
    String thesisAdvisor;
    String company;

    Scanner in = new Scanner(System.in);

    // print statements to match the database input 

    System.out.println("Now let's update a record");
    System.out.println("Please enter the student ID of the record you want to update >");
    studentID = in.next();
    System.out.println("Please enter the new First Name >");
    firstName = in.next();
    System.out.println("Please enter the new Last Name >");
    lastName = in.next();
    System.out.println("Please enter the new GPA[X.XX] >");
    gpa = in.nextDouble();
    System.out.println("Please enter the new Status [Active or Inactive] >");
    status = in.next();
    System.out.println("Please enter the new mentor >");
    mentor = in.next();
    System.out.println("Please enter the new level >");
    level = in.next();
    System.out.println("Please enter the new thesis Title >");
    thesisTitle = in.next();
    System.out.println("Please enter the new thesis Advisor's name >");
    thesisAdvisor = in.next();
    System.out.println("Please enter the new Company Name >");
    company = in.next();




//      stmt.executeUpdate("Update student Set studentID='" + studentID + "', firstName='" + firstName + "', lastName='" + lastName + "', gpa=" + gpa + "', status='" + status + "', mentor='" + mentor  + "', level='" + level + "', theseisTitle='" + thesisTitle + "', thesisAdvisor='" + thesisAdvisor + "', company='" + company + "WHERE studentID = '" + studentID + " '");





    stmt.executeUpdate("Update student Set studentID='" + studentID + "',firstName'" + firstName + "', lastName='" + lastName + "', gpa=" + gpa + "', status='" + status + "', mentor='" + mentor  + "', level='" + level + "', theseisTitle='" + thesisTitle + "', thesisAdvisor='" + thesisAdvisor + "', company='" + company + "WHERE studentID = '" + studentID + " '");

    // Close the statement and the connection

    stmt.close();
    conn.close();

} catch (Exception e) {
    System.err.println("ERROR: Either cannot connect to the DB " + " or error with the SQL statement");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:59:11+00:00Added an answer on June 14, 2026 at 11:59 am

    one problem with your query is that it produces syntax error on the firstname

    stmt.executeUpdate("Update student 
                        Set studentID='" + studentID + "',
                            firstName'" + firstName + "',                                          
                                     ^ here
    

    Another is, it is vulnerable with SQL injection. Please do parameterized your query, use PreparedStatement, example

    String updateQuery = ""
            + "UPDATE student "
            + "SET    firstname = ?, "
            + "       lastname = ?, "
            + "       gpa = ?, "
            + "       status = ?, "
            + "       mentor = ?, "
            + "       level = ?, "
            + "       theseistitle = ?, "
            + "       thesisadvisor = ?, "
            + "       company = ? "
            + "WHERE  studentid = ? ";
    
    PreparedStatement pstmt = con.prepareStatement(updateQuery);
    pstmt.setString(1,firstName)
    pstmt.setString(2,lastName)
    pstmt.setInt(3,gpa)
    pstmt.setString(4,status)
    pstmt.setString(5,mentor)
    pstmt.setString(6,level)
    pstmt.setString(7,thesisTitle)
    pstmt.setString(8,thesisAdvisor)
    pstmt.setString(9,company)
    pstmt.setString(10,studentID)
    

    Why do we use PreparedStatement?

    • to protect against SQL Injection
    • to protect against SQL Injection
    • to make the code more readable especially when you have large query

    SOURCE

    • PreparedStatement
    • PreparedStatement
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found many people with simliar issues but no soultions...basically I have two
I have two issues in this google chart. I want to either get rid
I currently have a one-page Bottle project working through localhost:8080 . For the purposes
I have code I am working on, but I am having issues populating the
THE INFO Currently I have two tables I am working with- a POST table
I am working on an assignment and have to create two classes, one represents
I need to override styles for two EditText instances. I have two issues regarding
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I'm having issues getting UpdatePanel working in a large, existing solution. I have a
So I'm having two issues that I cannot seem to get unkinked. I run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.