Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: SQL Error

  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SQL Error

    I am new to Java and getting a run time error in sql statement in the java code.

    Below is the test code. I want to select the row from CUSTOMER table where CUSTLOGINID = "abc"
    Code:
    String username = "abc";
    String sqlText  = "select CustId, CustLoginId, CustPassword from javaDB.Customer where custLoginId = ";
    
    stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sqlText + " '+username+' ");
    Please advice what is wrong in above code.

    Thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    And what is the error you are receiving?

    You may as well simplify this as well by making it a prepared statement. Prepared statements have many advantages over standard statements.

    Code:
    String username = "abc";
    String sqlText  = "select CustId, CustLoginId, CustPassword from javaDB.Customer where custLoginId = ?";
    
    PreparedStatement stmt = conn.prepareStatement(sqlText);
    stmt.setString(1, username);
    ResultSet rs = stmt.executeQuery();


  •  

    Posting Permissions

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