Results 1 to 2 of 2
  1. #1
    dilanka007 is offline Member
    Join Date
    Jan 2010
    Rep Power

    Exclamation jdbc problem!!! pls help

    Well this is the code i m working on... the commented statement work perfectly.. but i want the prepared statement to work..

    unfortunately prepared statement doesn't work..
    what am i doing wrong?
    once again! if i comment the prepared statement and uncomment the commented statement code fragments that does work..

    public void register(String username,String firstName,String lastName,String password) throws SQLException{

    String query = "insert into user(username, first_name, last_name, password) values(?, ?, ?, ?)";

    // i tried this too.. String query = "insert into user values(?, ?, ?, ?)";

    PreparedStatement pstmt = conn.prepareStatement(query);

    // the following works perfectly
    /* Statement statement = conn.createStatement();
    statement.executeUpdate("INSERT INTO user VALUES ( username,'mark','laws','mark123');") ;*/


  2. #2
    lompic is offline Member
    Join Date
    Apr 2010
    Rep Power


    well with preparedStatement you first have to declare the variables you are trying to set. for example you are setting pstmt.setString(1,username), first declare username as string then try again

Similar Threads

  1. jdbc problem!!! pls help
    By dilanka007 in forum New To Java
    Replies: 5
    Last Post: 01-16-2010, 05:07 PM
  2. problem with jdbc in jsp
    By nishant.4545 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-29-2009, 01:31 PM
  3. Problem in JDBC
    By Preethi in forum New To Java
    Replies: 11
    Last Post: 01-08-2009, 05:18 PM
  4. Jdbc problem
    By abhiN in forum JDBC
    Replies: 1
    Last Post: 03-21-2008, 05:10 AM
  5. JDBC problem
    By peiceonly in forum Threads and Synchronization
    Replies: 2
    Last Post: 08-03-2007, 01:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts