JDBC Insert Statement

  • 17 years ago

    I have this insert statement in my .jsp page. Sorry its kinda long but does anyone know whats wrong with it? Its giving me errors.


    Code:

    stmt.executeUpdate("INSERT INTO users (id,first,last,username,status,password,ext,fax,cell,pager,email,didPhone,isDivisionHead,
    role,comp,division) VALUES(," + first + "," + last + "," + username + ",0," + password +"," + extension + "," + fax
    + "," + cell + "," + pager + "," + email + "," + directDial + "," + isHead + "," + role + ",0," + division + ")");


    Thankyou in advance.

  • 17 years ago

    VALUES(,"


    is the problem - it should be VALUES("


    However, for security you should probably also be putting quotes around the strings within the SQL string, and checking for any quotes within the variables if they're from a posted form to prevent any sql injection attacks.

  • 17 years ago

    I did that already, that comma is there becuase the first field is auto increment. I think I figured it out thanks though.

  • 17 years ago

    u have some misstake


    ("INSERT.......") VALUES(","......);


    hope this help u


    the full code will be as below

    Code:

    stmt.executeUpdate("INSERT INTO users (id,first,last,username,status,password,ext,fax,cell,pager,email,didPhone,isDivisionHead,
    role,comp,division") VALUES("," + first + "," + last + "," + username + ",0," + password +"," + extension + "," + fax
    + "," + cell + "," + pager + "," + email + "," + directDial + "," + isHead + "," + role + ",0," + division ")");

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens