Results 1 to 5 of 5
  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default How to execute two different query

    hey,

    i want to execute two different query like that

    Java Code:
     PreparedStatement pst=con.prepareStatement("select DAYNAME('"+d+"')");
                 ResultSet rs=pst.executeQuery();
                 
                 while(rs.next()){
                     c=rs.getString(1);
                     
                     pw.println(c);
                 
                 
                 PreparedStatement chck=con.prepareStatement("select days from svlbl");
                 ResultSet rst=chck.executeQuery();
                 if(!"c".equals(rst.getString("days"))){
                     
                     pw.println("Available");
                 }
                 else{
                         pw.println("Sorry Not Available");
            }
                 
                 }

    but i only get result of first statement not second how to do

    Thanks

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to execute two different query

    Are you getting an exception?
    I would expect one looking at that code.

    If not, how are you handling exceptions?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default Re: How to execute two different query

    i am handle exfception using try n catch..

    i just want to ask that how to run that both statements...it is run only one ...

    it showing only DAY not compare that day to my database day column...

    so how to perform that??

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: How to execute two different query

    That code will throw an exception on line 12, which is why I ask how you are handling exceptions.
    Can you show your try/catch code?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: How to execute two different query

    You never call next() on the second ResultSet. It's not on the first record yet.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 0
    Last Post: 12-31-2016, 02:05 PM
  2. Replies: 1
    Last Post: 03-17-2016, 05:08 PM
  3. Replies: 3
    Last Post: 10-19-2012, 10:16 PM
  4. Why should you use PreparedStatement in Java to execute Query?
    By javin.paul in forum Reviews / Advertising
    Replies: 0
    Last Post: 06-20-2012, 04:32 PM
  5. Query taking lot of time to execute..
    By asgardar in forum Advanced Java
    Replies: 4
    Last Post: 01-19-2011, 07:09 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
  •