Results 1 to 5 of 5
  1. #1
    Dcalladi is offline Member
    Join Date
    Oct 2011
    Posts
    27
    Rep Power
    0

    Default SQL statement working in one class but not another

    Hi i have this SQL statement
    Java Code:
    ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM Users Where "+searchType+" = '"+searchText+"'");
    and this error
    SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name = 'Danny'' at line 1

    searchType can be First Name or Second name from a Combo box using String searchType = (String) Cbsearchby.getSelectedItem();
    and searchText something type in by user take using getText

    yes i have the exact same line in another class that works fine any pondering on the situation?

    Thanks

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: SQL statement working in one class but not another

    Use a PreparedStatement instead.

  3. #3
    Dcalladi is offline Member
    Join Date
    Oct 2011
    Posts
    27
    Rep Power
    0

    Default Re: SQL statement working in one class but not another

    can you use Prepared-statement for Query

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: SQL statement working in one class but not another

    Did you read about it in the Java API?

  5. #5
    Dcalladi is offline Member
    Join Date
    Oct 2011
    Posts
    27
    Rep Power
    0

    Default Re: SQL statement working in one class but not another

    yes i was sure that they only use them for update or insert statements

Similar Threads

  1. Java, if statement calling class
    By illinit in forum New To Java
    Replies: 5
    Last Post: 08-25-2011, 08:04 PM
  2. Problem understanding class statement.
    By martijnburger in forum New To Java
    Replies: 3
    Last Post: 07-21-2011, 11:07 PM
  3. Replies: 1
    Last Post: 05-17-2011, 09:43 AM
  4. if statement with strings not working... again
    By hardcorebadger in forum New To Java
    Replies: 4
    Last Post: 01-11-2011, 06:02 AM
  5. Update statement not working.
    By OMFGITSROHIT in forum JDBC
    Replies: 5
    Last Post: 04-08-2010, 01:03 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
  •