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

  • Home
  • SEARCH
  • 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 6795905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:24:10+00:00 2026-05-26T18:24:10+00:00

try { Statement stmt = con.createStatement(); stmt.executeUpdate(INSERT into emailacc(fname,lname,uname,mail,passwd,passwd2,date,month,year) values(‘+fname+,+lname+,+uname+,+mail+,+passwd+,+passwd2+,+date+,+selectMonth+,+year+’)); out.println(<h3><font color=’green’>Information Added Successfully.</font><br>

  • 0
try {
    Statement stmt = con.createStatement();
    stmt.executeUpdate("INSERT into emailacc(fname,lname,uname,mail,passwd,passwd2,date,month,year) values('"+fname+","+lname+","+uname+","+mail+","+passwd+","+passwd2+","+date+","+selectMonth+","+year+"')");
    out.println("<h3><font color='green'>Information Added Successfully.</font><br> You Are a registered User now.</h3><br>");
    con.close();
} catch(Exception e) {
    out.println("Exception caught : "+e);   
}

Why is it happening?
Last time I did the same but it didn’t happen, whats wrong with it?

  • 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-05-26T18:24:11+00:00Added an answer on May 26, 2026 at 6:24 pm

    Is because you are omitting single quotes, for avoid this mistakes my recommendation is to use PreraredStatement, also in order to proper close connection it mus be in a finally block , you code must look at this:

        try {
            PreparedStatement stmt = con.prepareStatement("INSERT into emailacc(fname,lname,uname,mail,passwd,passwd2,date,month,year) values(?,?,?,?,?,?,?,?,?)");
            stmt.setString(1,fname);
            stmt.setString(2,lname);
            stmt.setString(3,uname);
            stmt.setString(4,mail);
            stmt.setString(5,passwd);
            stmt.setString(6,passwd2);
            stmt.setDate(7,date); //you need convert your date to java.sql.Date if 'date' field of database is of type date. If not setString is fine
            stmt.setInt(8,selectMonth);
            stmt.setInt(9,year);
            stmt.executeUpdate();
            out.println("<h3><font color='green'>Information Added Successfully.</font><br> You Are a registered User now.</h3><br>");
        } catch (Exception e) {
            con.rollback();
            out.println("Exception caught : " + e);
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch(SQLException ex){
                    //DO NOTHING
                }
            }
        }
    

    You can learn more of PreparedStatemt in:

    http://download.oracle.com/javase/tutorial/jdbc/basics/prepared.html

    A final note: PreparedStament are more efficent thant Statement and avoid the SQL Injection hack so PrepararedStatement is more secure. Try use always a PreparedStatement

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

Sidebar

Related Questions

If I try this statement: INSERT INTO TerminalEventChild (id,stringValue) VALUES (64,'version123|'); MySQL fail with
String query = select email from emp_select; Statement stmt; try { DB db=new DB();
My problem is that I have to set a variable in a try statement
What is the intended use of the optional else clause of the try statement?
Is it good practice to have more than one try{} catch{} statement per method?
What is the proper place to explain error handling in a try-catch statement? It
How should I prepare the code if it something fails? With try-catch statement or?
The using(...) statement is syntactic sugar for try{} finally {}. But if I then
I try to use the SQL statement SELECT * FROM table ORDER BY column
When I try to execute this statement in Oracle SQL Developer 2.1 a dialog

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.