Troubled with PreparedStatement, please help

Hello all:
Here is a seemingly too simple a problem which is already taking my day. Please help.
String x=null;
String querry1 = null;
String querry2 = null;
ResultSet rs = null;
Statement st = null;
PreparedStatement pstmt = null;
try {
st = conn.createStatement();
//MAKE FIRST QUERRY
querry1 = "SELECT * FROM table1 WHERE (a= ? OR b = ?)";
pstmt = conn.prepareStatement(querry1);
pstmt.setString(1, userInput);
pstmt.setString(2, userInput);
rs = pstmt.executeQuery();
while(rs.next()){
//Process the result set.
//The value of x is one of the values in the result set.
//Hence get it.
x = rs.getString("C");
     }//end while
//No problem up to here.
//For check, output the value of x
System.out.println(x); //correct non-null value is displayed
//MAKE SECOND QUERRY based on the value of 'x'
querry2 = "SELECT * FROM table2 WHERE C= ? ";
//Table 1 and table 2 have a common column C.
//I want to retrieve the value from table 2 for which C=x;
pstmt = conn.prepareStatement(querry2);
pstmt.setString(1, x);
rs = pstmt.executeQuery();
//The problem is that in this 2nd querry, SQL error is caught, with the message
"java.sql.SQLException: Illegal operation on empty result set"
//whereas it should have produced a valid value.
//When the querry is formed explicitly (as follows), there is no problem. Result set is OK.
//when the value of x is "mystring", then the follwoing 3 lines work
pstmt = conn.prepareStatement(querry2);
pstmt.setString(1, "mystring");
rs = pstmt.executeQuery();
Please teach me what the hell I'm not getting here.
Thank you.

I would have thought you'd get this exception:
"java.sql.SQLException: Illegal operation on empty result set"
because you're trying to call something like:
rs.getString("foo");on an empty ResultSet. You can test whether the ResultSet has any rows as ResultSet.next() returns a boolean value, i.e.:
if (rs.next())
    rs.getString("foo");
}So the question is why is your second ResultSet empty? Maybe the value of C you are getting from table1 has leading/trailing whitespace that is not in table2?

Similar Messages

  • Iphone 5 trouble with charging, please help?

         Haven't had my iPhone for long (around November for my birthday) and for about the last couple of weeks recently I have had major trouble with the battery charge.
         At first I thought it was the cables, so I got new one after new one and they'd work but then stop working. Until the last one I just purchased, it pretty much stopped charging the phone straight away. No lightening or sound response, no connection via computer etc. So, when my charge ran out I still had it plugged into my computer and now my phone only chargers when it's off when it's plugged into a USB port (bear in mind, it doesn't connect to iTunes-it says USB is unrecognized although it still chargers the phone when off). However, it charges fairly quickly when off but when in use the charge diminishes just as quick as it takes to charge. Not only that but now whenever I wish to turn my iPhone off, it turns itself back on.
          I have recently sent off my phone to the Apple store to have it checked over and it came back to me saying they couldn't reproduce the symptons I had mentioned so there was me thinking everything was fine but nope, still faulty. So a bit disappointed with paying £7.00 for delivery to have nothing been done about it (not only that, but the phone as also out of charge when returned so it just seemed like my phone wasn't looked over one bit). Also a bit disappointed and annoyed at the fact I'm still paying for my monthly contract for the phone when I am unable to use it!!!
         I haven't damaged the phone (it basically looks brand new) and haven't exposed it to any liquids. The USB port on my phone where I charge it seems clear too.
          The annoyance of having to send it back to Apple costing me more money is offputting so does anyone have any other suggestions? I'm going to my local 3 store to see if they can help me out but I'm just a bit fed up now. Can see this is a popular problem amongst other iPhone users too.
    Many thanks!
    (Oh and need to add I HAVE updated everything on my phone, restored everything, restarted etc.)

    Yeah I went to the 3 store and they said that it costs if they find it's a software issue (which I believe isn't fair). However, after sending mine off and having it back exactly the same I headed off to the 3 store and asked to see what they could do for me. Of course, they can't touch Apple phones so they kindly phoned Apple again for me to only say that Apple have NO record of me even sending my phone off even though I have written and e-mail proof. They then said that they replaced my phone in which they didn't. So I spoke to the senior supervisor who said for me to send it off again (yawn) but to be replaced and if it doesn't then I have to e-mail her directly. It's such an annoying issue because I'm still paying for my phone when I can't even use it.
    My advice is, definitely go to the store. Even-though they can't actually replace it there and then or send it off themselves to be repaired but they (should) phone up Apple and help you further. Apple shouldn't be asking you for such an upfront cost without even looking at your phone as it could be another issue.
    That's me up to date. Sending it off tomorrow, hopefully receive a replaced working phone now.

  • After installation trouble with lightroom **please help me**

    When i installed lightroom (3.6 and 4) i keep getting this error message that says " unexpected error opening catalog" i can't use or open lightroom< it doesn't give me specific details as to why it's not working. I've tried to update my computer with the services packs that it says in the requirements section when you download and i keep getting an error that won't allow it to update. I've tired using microsoft fix it and system update readniness tool to help update. My laptop is a windows 7 home premium. please help me on to fix this problem

    Have you used it before?  It sounds like it's open a default - and corrupt - catalog.
    You can create a new one and start from scratch by holding down control as you start it.

  • Loads of trouble with n73, please help me.

    Ok, I bought the n73 about a month ago, and I've been happy with it. A bit on the slow side, but acceptable.
    Now since about a week, the damn thing has been driving me crazy. First, it started losing network connection, no calls in or out. So I went through the menu, thinking I can find the problem. Then the phone starts crashing. First only once or twice, no nearly 70% of the time I cannot do ANYTHING with it. The nokia screen shows up and no buttons, not even the on/off button, work. Sometimes it starts working by itself in a few minutes, but usually it just stays that way. I have tried to update the software, but everytime I try to connect, either the connection breaks off or it crashes. I downloaded the pc software, but it wont connect that way either.
    I'm really starting to think it hardware based, since I never dropped it or gotten it wet or anything. But I'm still hoping someone here knows how to deal with this. Please help me!

    Have you used it before?  It sounds like it's open a default - and corrupt - catalog.
    You can create a new one and start from scratch by holding down control as you start it.

  • TS1424 Hey everyone I'm having trouble with iTunes please help ASAP thank you.

    Hey I just bought an iPad and I can't connect to iTunes, seeing as I'm using my iPad right now I know the wifi works, I've tried a lot of different things and read the apple site for help but nothing worked, please help me thank you.

    http://support.apple.com/kb/HT1923?viewlocale=en_US
    this worked perfectly for me, with no loss of library! BUT was warned about uninstalling things in the order listed...FYI.

  • Much trouble with imports - please help!

    Very frustrated here! When I put a CD into my computer drive, nothing happens at all. It's not recognised, not only in iTunes but in My Computer too. This has happened for a while. When, very occasionally, I find that the CD is recognised by iTunes only the first few seconds/minutes are recorded or the real time is overridden by something like 782:34:23 and the song doesn't play at all. I know others have had this problem too, but I just wanted to post my CD diagnostic in the desperate hope that anyone out there has a solution or suggestion.
    I have re-installed iTunes and suchlike but this doesn't help so I assume it's something clever and technical that I have to do...
    Anyway here's the diagnostic:
    Microsoft Windows XP Home Edition Service Pack 2 (Build 2600)
    Dell Computer Corporation Dimension 2400
    iTunes 6.0.1.3
    CD Driver 2.0.4.3
    CD Driver DLL 2.0.3.2
    LowerFilters: PxHelp20 (2.0.0.0), drvmcdb (1.0.0.1), sscdbhk5 (1.0.0.1),
    UpperFilters: GEARAspiWDM (2.0.4.3),
    Video Driver: Intel(R) 82845G/GL/GE/PE/GV Graphics Controller\Intel(R) 82845G /GL/GE/PE/GV Controller
    Found aspi32 running.
    Thanks tons in advance.
    KW
    Dell   Windows XP  

    Toonz,
    Sorry it's taken a while to reply, haven't had access to my computer for a few days.
    I downloaded the iTunes you suggested, here are the CD diagnostics:
    Microsoft Windows XP Home Edition Service Pack 2 (Build 2600)
    Dell Computer Corporation Dimension 2400
    iTunes 6.0.2.23
    CD Driver 2.0.4.3
    CD Driver DLL 2.0.3.2
    LowerFilters: PxHelp20 (2.0.0.0), drvmcdb (1.0.0.1), sscdbhk5 (1.0.0.1),
    UpperFilters: GEARAspiWDM (2.0.4.3),
    Video Driver: Intel(R) 82845G/GL/GE/PE/GV Graphics Controller\Intel(R) 82845G /GL/GE/PE/GV Controller
    Found aspi32 running.
    IDE\DiskWDCWD400BB-75FRA0_____________________77.07W77, Bus Type ATA, Bus Address [0,0]
    IDE\CdRomSAMSUNGCDRW/DVD_SM-352F________________T902___, Bus Type ATA, Bus Address [0,0]
    If you have multiple drives on the same IDE or SCSI bus, these drives may interfere with each other.
    Some computers need an update to the ATA or IDE bus driver, or Intel chipset. If iTunes has problems recognizing CDs or hanging or crashing while importing or burning CDs, check the support site for the manufacturer of your computer or motherboard.
    Current user is administrator.
    D: SAMSUNG CDRW/DVD SM-352F, Rev T902
    Unclosed disc in the drive.
    Get drive speed succeeded.
    The drive CDR speeds are: 48.
    The drive CDRW speeds are: 48.
    Thanks so much.
    Kx

  • TS4009 Trouble with iPad,please help

    I keep getting a message on my ipad every few mins saying my storage is almost full,so I purchased 10 GB of storage space and Im still getting this annoying message,any ideas what I need to do to stop this?

    sorry to tell you but you've done exactly the wrong thing trying to fix the problem. It's extremely unlikely that your problems were caused by a fault in the application itself. They were almost certainly caused by a bad preference file (may be more than one) in your home directory or an application conflict with something else like a bad plugin. Normally, it's easy to reinstall safari from the leopard install DVD. open the DVD in finder, go to optional installs and double-click on Optional Installs.mpkg. Follow the instructions and on the screen with the choice of software to install choose safari. after you are done you'll need to rerun the 10.5.3 combo update and possibly safari 3 update to bring safari up to the current version. This might fix it. However, because you used AppDelete it might not fix it as it may have deleted various necessary system files when you deleted safari.

  • I have trouble with megaupload, please help!!!!!

    i used to donwload from megaupload normally. since last week, i could not download anything from mega. First I wait 45 second, and then I click to download button. It just stayed there instead it should pop up the download windows like normal. Can some one help me to fix this problem

    Or to not be a jerk like the guy above, try recovering it through itunes.
    Step 1
    Open iTunes and connect the iPhone via USB.
    Step 2
    Press and hold the Home button and the Sleep/Wake button at the same time.
    Step 3
    Continue holding the both buttons until your iTunes pops up a message telling you that it has detected an iPhone/iPod in recovery mode.
    Good Luck!

  • HT2953 i-tunes could not be used because the original file could not be found.could not locate.this error occurs on most of my songs in my library and will not play even though they are in my i-pod and play with no trouble.can  anyone please help?

    i-tunes could not be used because the original file could not be found.could not locate.this error occurs on most of my songs in my library and will not play even though they are in my i-pod and play with no trouble.can  anyone please help?

    I was not complete clear.
    Since you never changed the settings in the advanced section of iTunes preferecnes, you have to chech that your music is really in the location setted in the folders reported in the advanced section.  If not you have 2 ways: reset the position of this folders or in the actual disk organisation or in the pointing on the preferences.
    If you press the reset button you just give to itunes its default setting as for the position of the music files: probably this will be a good choice if you have never changed any default preference.
    But before I would check the folders and see if the songs are really there
    In my iTune I have this, and I believe it is the default.
    Users/YOURHOMEFOLDERNAME/Music/iTunes/iTunes Music

  • Trying to veiw videos from a website that requires me to download firefox and silverlight.My imac osx 10.5.8 will now download firefox. firfx tells me my mac is not compatible with ffox Please help me ?  Thank you

    trying to veiw videos from a website that requires me to download firefox and silverlight.My imac osx 10.5.8 will now download firefox. firfx tells me my mac is not compatible with ffox Please help me ?  Thank you

    There is a version of Firefox 4 available for PPC Macs:
    TenFourFox 4.0.1 Firefox 4 For PowerPC Browser Released
    Version 4.0.1 of TenFour Fox, FloodGap's port of Firefox 4 for Power PC
    Macs that supports both Mac oS X 10.4 and 10.5. has been released.
    Mozilla.org dropped support for OS 10.5 after Firefox 3.6 and for Power
    PC with the fourth beta of Firefox 4.
    TenFourFox uses almost all the same code as Firefox 4 and has nearly all
    the same features, including faster JavaScript, WebM video, and HTML 5
    and CSS 3 support, as well as new and emerging Web features, but with
    the code needed to keep your Power Mac functional and fast. Out of beta
    and it's ready for action, versiob 4.0.1 is a performance, security and
    stability update incorporating Mozilla's Firefox 4.0.1 plus AltiVec acceler
    -ation for WebM and browser graphics, and G5 JavaScript acceleration.
    For more information, visit:
    http://www.floodgap.com/software/tenfourfox/
    Source: from http://www.applelinks.com - posted April 25, 2011)
    Now for the intersting bit: TenFourFox, like Firefox, does not support most plug-ins. Unless you are prone to headaches (in which case don't) you can read about that here:
    http://code.google.com/p/tenfourfox/wiki/PluginsNoLongerSupported
    But there is a workaround!
    Open TenFourFox and type in the address bar: about:config (no spaces) and click return. This gives you a warning that it might harm the application. Ignore that and click on 'I'll be careful, I promise' and you get the config file that you can edit - with great care.
    Look/search (scroll down) for: tenfourfox.plugins.enabled
    Set it to true. (Double click it to toggle it)
    Now close TenFourFox, open it again, and Flash will now work, as it now uses the plug-ins that Safari has stored.
    With SilverLight, Microsoft attempted to create their own version of what a replacement for Flash could be - but not to universal acclaim. You can read more about it here:
    http://silverlight.net/
    So, if you go to any sites that have been designed for this new Silverlight stuff, you can download the plug-in from here (but make certain that you are downloading SilverLight v.1.0 for OS X (10.4.8 upwards) if you are using a PPC Mac, but even this will not work with Safari 4. Version 2 only works with Intel Macs and does work with Safari 4/5. The solution is to download and install the latest version of Flip4Mac, which now includes a Silverlight component:
    http://dynamic.telestream.net/downloads/download-flip4macwmv.htm
    But the latest news is that Microsoft will probably abandon Silverlight in favour of HTML5:
    http://www.appleinsider.com/articles/10/10/29/apples_ios_pushes_microsoft_to_dia l_down_silverlight_for_html5.html  and
    http://www.bbc.co.uk/news/technology-11673384

  • I just installed mongolian cyrillic keyboard and it's working just fine with safari but i can't type on Word with it. please help me?

    i just installed mongolian cyrillic keyboard and it's working just fine with safari but i can't type on Word with it. please help me?

    PS Here is a source for a keyboard.  Try it if you have not done so already
    http://m10lmac.blogspot.com/2012/12/new-mongolian-keyboard-layout.html
    For questions about why Word doesn't do something, try
    http://answers.microsoft.com/en-us/mac/forum/macword

  • When I make a call or recieve a call, the voice of the other person is not heard. but speaker phone works. what could be the trouble. could you please help me in resolving this? iPhone 4, iOS 6.1.3

    when I make a call or recieve a call, the voice of the other person is not heard. but speaker phone works. what could be the trouble. could you please help me in resolving this? iPhone 4, iOS 6.1.3.i had purchased my iphone 4  factory unlocked from usa last month.i am from india so will any apple service centre help me for this issue?

    They will help you just make sure that you make a appointment before you go into the store. Also if the iPhone needs to be replaced and you are not within your year of hardware coverage, that is when they will ask you to pay a fee.

  • I can't turn off find my ihone, always show "there was a problem when canceling the registration of this iphone with icloud" please help me. i can't restore my iphone before turn off find my iphone

    i can't turn off find my ihone, always show "there was a problem when canceling the registration of this iphone with icloud" please help me. i can't restore my iphone before turn off find my iphone

    If you are the original owner of the phone and know the Apple ID and password that were used to activate it originally, and if you have an existing backup to restore from, you can force it into recovery mode (which will completely erase it) and restore it as explained here: If you can't update or restore your iPhone, iPad, or iPod touch - Apple Support.  When you do you will encounter activation lock, and will have to provide the ID and password used to activate it originally in order to activate it again.  If you can't, you won't be able to activate and use it.

  • I'm trying to set up my new iPhone 5s from a backup of my previous iPhone, when trying to enter my Facebook login info in settings I keep getting the following error message : error signing in could not communicate with server, please help !

    I'm trying to set up my new iPhone 5s from a backup of my previous iPhone, when trying to enter my Facebook login info in settings I keep getting the following error message : error signing in could not communicate with server, please help !

    Can you access other apps? Can you acess the internet? Can you access applications that use internet besides facebook?
    If answer is yes to all of these; contact Facebook.

  • My factory unlocked iphone 4s mms is not working with tmobile, please help...

    my factory unlocked iphone 4s mms is not working with tmobile, please help...

    Check out this link. It should fix the problem
    http://support.t-mobile.com/thread/17918?tstart=0

Maybe you are looking for