Results 1 to 4 of 4

Thread: Query MySQL

  1. #1
    boss is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

    Default Query MySQL

    Hi,

    I'm using MySQL.

    When I try to make a query (ex. "SELECT * FROM table WHERE Code = c), it doesn't return anything, because it doesn't recognize var c inside the query, and throws a SQLException. How do I get around this?



    Thanx,

    Hugo

  2. #2
    adz
    adz is offline Member
    Join Date
    Jul 2009
    Posts
    35
    Rep Power
    0

    Default

    erm do
    Java Code:
    String c = "somecode";
    String query = "SELECT * FROM table WHERE Code = " + c;

  3. #3
    boss is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

    Default

    Ok, thanx...

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Except, of course, that won't work since you haven't used any quotes in the query around c.
    A PreparedStatement might be a better bet...

Similar Threads

  1. mysql query performance issue
    By gilbertsavier in forum JDBC
    Replies: 0
    Last Post: 08-05-2009, 10:34 AM
  2. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  3. MySQL/JDBC Prepared Statement Select query
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-12-2009, 05:29 PM
  4. Mysql/JDBC update query problem
    By thelinuxguy in forum Advanced Java
    Replies: 3
    Last Post: 02-11-2009, 09:56 PM
  5. Replies: 1
    Last Post: 08-22-2008, 06:28 PM

Posting Permissions

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