Results 1 to 8 of 8
  1. #1
    prabhurangan is offline Member
    Join Date
    May 2008
    Posts
    69
    Rep Power
    0

    Question [SOLVED] General string problem in my database query.....?

    Hi Members,
    String query = "Select * from table1 join table2 on tb1 = tb2 join table3 on tb2 = tb3 where tb1.id = 2 and tb2.name= 'john' and tb3.descriptionId=5";

    This is my string but when i compile and run this im not getting any result for this query, so i made a system.print for this string query and my print statements looks like this:

    "Select * from table1 join table2 on tb1 = tb2 join table3 on tb2 = tb3 where tb1.id = 2 and tb2.name= 'john
    ' and tb3.descriptionId=5".

    Please have a look at this in my WHERE class that tb2.name, and if i join the 2nd line and 3rd line, im getting the result for my query; but im not sure why it is acting so.

    Please help me out in this....

    Looking forward for your reply..

    Regards,
    Prabhu.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    prabhurangan is offline Member
    Join Date
    May 2008
    Posts
    69
    Rep Power
    0

    Default

    Hi Eranga,
    Great to see you again, in my query you can see it in two lines, in that my 1st line ends with "tb2.name='john " can you see that and the ending "single cotes...... ' " is continued in the second line..... can you see that......

    1st line: Select * from table1 join table2 on tb1 = tb2 join table3 on tb2 = tb3 where tb1.id = 2 and tb2.name= 'john
    2nd line: ' and tb3.descriptionId=5"

    As string should be within ' ' single cotes, using mysql.....

    Can you get me Eranga....
    If not please let me know...

    Regards,
    Prabhu.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Why don't you try like this.

    Java Code:
    String query = "Select * from table1 join table2 on tb1 = tb2 join table3 on tb2 = tb3 " +
    "where tb1.id = 2 and tb2.name= 'john' and tb3.descriptionId=5""

  5. #5
    prabhurangan is offline Member
    Join Date
    May 2008
    Posts
    69
    Rep Power
    0

    Default

    How can we do so? It will throw "unclose string literal" error?
    Before I got the same problem then i renamed my method name and then compiled and ran it, it was fine, but now again i face this problem.

    Regards,
    Prabhu.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    So my friend, simply close it. I made a little mistake there.

    Java Code:
    String query = "Select * from table1 join table2 on tb1 = tb2 join table3 on tb2 = tb3 " +
    "where tb1.id = 2 and tb2.name= 'john' and tb3.descriptionId=5";

  7. #7
    prabhurangan is offline Member
    Join Date
    May 2008
    Posts
    69
    Rep Power
    0

    Default

    Hi Friend,
    Sorry i have made some mistakes, the parameter which im passing to WHERE class has some extra space, so now i tried using "trim()" and everything works fine.

    Will meet you on next post.

    FYI,
    I have posted a topic related to 'struts 2 help...' are you watching it buddy. Please I need seniors like you to help me on that.

    Thank you,
    Prabhu.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Java Popup Window & Url Query String Value
    By Rivelyn in forum New To Java
    Replies: 4
    Last Post: 01-20-2011, 05:03 AM
  2. Query in database
    By anki1234 in forum JDBC
    Replies: 3
    Last Post: 08-20-2008, 05:45 PM
  3. ms access jdbc query problem
    By Fleur in forum New To Java
    Replies: 2
    Last Post: 04-30-2008, 06:55 PM
  4. How to query data from database using SSL
    By mano in forum New To Java
    Replies: 0
    Last Post: 08-02-2007, 05:30 PM
  5. Displaying different columns with database query
    By jennybgh in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-02-2007, 05:04 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
  •