PreparedStatement & MySql not working ! Why ?!!?

Hello everyone. One question for you : I try to have a SELECT on a table to get a column value. I've used for that a preparedstatement but id didn't worked, I mean it returned nothing. Then I've used a simple statement which worked correctly. My question is why prepared doesn't work while simple statement do ?! Other querys work fine, but this one doesn't. And I simply don't get it... I need this preparedstatement way because I use this query very often.
I use MySQL Connector/J latest version, Java 1.4. Here's the code for this situation:
This doesn't work:
String sql = "SELECT IDUSER FROM SUBSCRIBERS WHERE MSISDN = ? AND SUBSCRIBER_TYPE = 0 AND RIGHTS <> 1 LIMIT 1";
PreparedStatement pstm = null;
ResultSet rs = null;
pstm = serviceConnection.prepareStatement(sql);
pstm.setString(1, MSISDN);
rs = pstm.executeQuery();
//gets the iduser from the query
if (rs.next())
iduser = rs.getInt("IDUSER");
else
iduser = 0;
This works:
String sql = "SELECT IDUSER FROM SUBSCRIBERS WHERE MSISDN = "+MSISDN+" AND SUBSCRIBER_TYPE = 0 AND RIGHTS <> 1 LIMIT 1";
Statement stm = null;
ResultSet rs = null;
stm = serviceConnection.createStatement();
rs = stm.executeQuery(sql);
//gets the iduser from the query
if (rs.next())
iduser = rs.getInt("IDUSER");
else
iduser = 0;
Thank's in advance.

MSISDN is a String or is a number?
The non PreparedStatement code works if the sql has
quotes arrounf this field?
String sql = "SELECT IDUSER FROM SUBSCRIBERS WHERE
MSISDN =' "+MSISDN+"' AND SUBSCRIBER_TYPE = 0 AND
RIGHTS <> 1 LIMIT 1";
This is something simmilar to the use of
PreparedStatement.setString();
The setters of prepared statements are not a simple
substitution in the sql string. Your database probably
are thinking that there aren't any row with "not a
number" in the MSISDN column.The MSISDN is a String representation of a number. And it works with/without the ' around for statements. What's strange is that if I change the prepared statement to be like this:
String sql = "SELECT IDUSER FROM SUBSCRIBERS WHERE MSISDN = "+MSISDN+" AND SUBSCRIBER_TYPE = 0 AND RIGHTS <> 1 LIMIT 1",
and I don't use the setString() method it still doesn't work :((

Similar Messages

  • My ipad camera is not working why? Help

    My ipad camera is not working, why? Please help!!

    HI Judejesalva,
      You can restore your ipad to your factory settings it could be that the camera is having an error with the camera software.

  • Hello, I just did an update and now the second Language - Hebrew - does not working. why?

    Hello, I just did an update and now the second Language - Hebrew - does not working. why?

    More information please.
    If you are on adobe cloud, download indesign that support hebrew from CC desktop. Click on the preference gear on the top right then select App language.

  • HT2731 i already make my apple id but it not working why?

    sir i make id but not working why?

    What happens when you try to use it ? When you create an account you should get a email which you will need to open and click on the 'verify now' link in it.
    If it's a different problem ... ?

  • I have tried to reinstall CS3 extended student version to my new comuter from the dvd and also from the web download but it does not work - I get the information that the server does not work- why. How should I do?

    I have tried to reinstall CS3 extended student version to my new comuter from the dvd and also from the web download but it does not work - I get the information that the server does not work- why. How should I do?

    Well the error message is in Swedish but says: The installation program database is damaged. Please contact the Adobe support (which is a hard thing to do!!). I use Windows 7 Home Premium with service pack 1.
    Från: Mylenium 
    Skickat: den 29 december 2014 16:48
    Till: Tony Bohman
    Ämne:  I have tried to reinstall CS3 extended student version to my new comuter from the dvd and also from the web download but it does not work - I get the information that the server does not work- why. How should I do?
    I have tried to reinstall CS3 extended student version to my new comuter from the dvd and also from the web download but it does not work - I get the information that the server does not work- why. How should I do?
    created by Mylenium <https://forums.adobe.com/people/Mylenium>  in Downloading, Installing, Setting Up - View the full discussion <https://forums.adobe.com/message/7050595#7050595>

  • My network is not working i am in ghana and i use MTN  network but it is not working why is it like that

    my network is not working i am in ghana and i use MTN  network but it is not working why is it like that... pls get back to me now

    It sounds as if you need to call your mobile carrier.

  • I just bought a brand new iphone 5c and the home button is not working , why is that ?

    I just had a brand new iPhone 5c and the home button is not working , why is that ?

    then contact apple for warranty support or return the phone

  • I have iPhone 4S with new ios7, and panorama wallpaper doesn't work ! It let me shoose it, but it's not work, why?

    I have iPhone 4S with new ios7, and panorama wallpaper doesn't work ! It let me shoose it, but it's not work, why?

    These prices are for the U.S.
    Out-of-Warranty Service
    If you own an iPhone that is ineligible for warranty service but is eligible for Out-of-Warranty (OOW) Service, Apple will service your iPhone for the Out-of-Warranty Service fee listed below.
    iPhone model          Out-of-Warranty Service
    iPhone 5          $229
    iPhone 4S          $199
    iPhone 4, iPhone 3GS,
    iPhone 3G, Original iPhone          $149
    A $6.95 shipping fee will be added if service is arranged through Apple and requires shipping. All fees are in U.S. dollars and are subject to local tax.
    When setting up out-of-warranty service, Apple will request credit card pre-authorization for the maximum service fee listed above.  This amount will be deducted from your credit limit. The final service fee we charge will be determined during testing and may be less than the service fee listed above.
    Certain damage is ineligible for out-of-warranty service, including catastrophic damage, such as the device separating into multiple pieces, and inoperability caused by unauthorized modifications. However, an iPhone that has failed due to contact with liquid may be eligible for out-of-warranty service.
    Apple reserves the right to determine whether or not your iPhone is eligible for Out-of-Warranty service. iPhones that are repaired or replaced have a 90-day limited hardware warranty or assume the remainder of your standard warranty or AppleCare service contract coverage, whichever is longer. Please see Apple's Repair Terms And Conditions for further details.

  • The Restriction option to NOT ALLOW CHANGES to Mobile or Cellular data does not work why is this ?

    The Restriction option to NOT ALLOW CHANGES to Mobile or Cellular data does not work why is this ?

    Hi there,
    You may want to try force closing all open apps and resetting the device as an initial troubleshooting step. Take a look at the articles below for more information.
    iOS: Force an app to close
    http://support.apple.com/kb/ht5137
    Turn your iOS device off and on (restart) and reset
    http://support.apple.com/kb/ht1430
    Additionally, you may want to try completely disabling and re-enabling restrictions.
    -Griff W.

  • My new iPhone 4S speaker not working why?

    my iPhone 4S iOS 7.0.3,model MF266HN/A,8GB one speaker not working why? What can I do?

    All iPhones are mono. Stereo is only available on Earphones.
    Bottom left is mic and right is the speaker.

  • I have downloaded skype, but after synchronizing with itunes skype not working, why?

    i have downloaded skype, but after synchronizing with itunes skype not working, why?  when I was synchronizing I believe there was some message in itune saying software not backed up or somethin to that effect.

    Thanks for your response.
    However, I did not find any solution to my problem.
    in my phone the skype application skype is not opening up, same is the caseiwth mobile voip. Both these applications were downloaded last night and it worked then, but not working now.
    Thanks in advance for anyone willing to help. I am new to the iphone.

  • 1.4 - Important sites will not work & why are the AIM / Facebook contacts integrated with my phone contacts?

    Two issues I am having with my phone.
    1 - Before upgrading to the 1.4 software patch, I was able to visit some sites that I use regularly, one being www.hotschedules.com. I bartend and use my phone to look at my weekly schedule but now it will not work. Just to test it, I used a buddies phone who had not upgraded to 1.4 and the site opened JUST FINE!
    2 - I want to use facebook and AIM on my phone but for some (stupid?) reason, ALL of my facebook and aim contacts get listed in the SAME LIST as my phone contacts. I do NOT want to scroll through hundreds of contacts to find someone. Yes I know there are shortcuts but why even do this in the first place?

    Hello eculley and welcome to the forums;
    I attempted the website you mentioned, and it loaded fine on 1.4.1.1 on my Sprint Pre. We did identify some issues with websites on 1.4, and this should be resolved with 1.4.1. I know 1.4.1 is not available for Verizon yet, however it should be available soon.
    As for Facebook contacts, they show in the Synergy contact list by design, so that you can see all of your contacts in one master list. If you do not want those contacts showing in your Contacts app, you can open Preferences & Accounts for contacts and remove any account you don't want to see contacts for.
    Hope this helps!
    TreoAide

  • SMS relay via Iphone 6 NOT working - why?

    Hey all.
    So I upgraded to Yosemite. Looks nice.
    The "receive calls on your Mac" feature works fine on both my MacBook Air and my iMac. Not sure how much I'll use it though.
    However, the function where you can send non iMessage texts via iMessage (i.e. regular SMS) is NOT working for some odd reason.
    I get the usual "red" on the name I'm trying to send a message to and an error pop-up that this person is not hooked up to iMessage.
    Shouldn't this just work? Or is there something I need to do tick off first?
    I can place calls on my iPhone 6 via my Macs just fine - it's just the SMS function that's not active for some reason.
    Hope someone can help - because this is a function I've really looked forward to and know I'll be using a LOT.
    Best,
    Jesper

    I saw somewhere else in the forums that this  feature would work as of iOS 8.1 due out Monday....  but honestly don't know if there's any basis to that...  it's just a couple of days... why don't you wait and install iOS 8.1 on your phone and then try again...

  • My app store is not working why?, my app store is not working why?

    hy
               i want to now why i my itunes and app store is not working?and how can i send data from laptop to my iphone4?
               one more thing is that why safari cannot download any thing from web?

    Not sure what you mean by "not working" so without further information it's difficult to make a suggestion. As a shot in the dark.....
    Sign out of your ID in Settings>iTunes & App Store, restart the iPad and sign in again.
    Or ....You can try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your app preferences and device settings again.

  • Applet not Working.Why???

    I have written an applet program but it does not work
    It works when i did it as an application.
    I have installed JAVA plug in.The HTML and Applet codes
    are in the same directory as JDK
    The web browser comes up with a grey area & the following messages:
    Exception:java.lang.ClassNotFoundException:testing4.class
    (on the grey area)
    Applet testing4 not loaded (at the bottom of the browser)
    Why is this so?
    The code i have used are as follows:
    HTML CODE
    <html>
    <title>LPC
    </title>
    <applet code="testing4.class"  width=400 height=110>
    </applet>
    </html>APPLET PROGRAM CODE
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    //import java.lang.Object;
    public class testing4 extends JApplet
    { private JTextArea display;
      private JScrollPane scrollPane2;
      private JButton paste;
      private JPanel P2;
      private File fileName;
      public void init()
        paste=new JButton("paste");
        paste.setMinimumSize(new Dimension(90,20));
        paste.setPreferredSize(new Dimension(90,20));
        paste.setMaximumSize(new Dimension(90,20));
        copyhandler pa=new copyhandler();
        paste.addActionListener(pa);
        display=new JTextArea();
        scrollPane2=new JScrollPane(display);
        scrollPane2.setVerticalScrollBarPolicy(
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane2.setMinimumSize(new Dimension(200,58));
        scrollPane2.setPreferredSize(new Dimension(200,58));
        scrollPane2.setMaximumSize(new Dimension(200,58));
        P2=new JPanel();
        P2.setMinimumSize(new Dimension(200,80));
        P2.setPreferredSize(new Dimension(200,80));
        P2.setMaximumSize(new Dimension(200,80));
        P2.setLayout(new BoxLayout(P2,BoxLayout.Y_AXIS));
        scrollPane2.setAlignmentX (Component.LEFT_ALIGNMENT);
        P2.add(scrollPane2);
        paste.setAlignmentX(Component.LEFT_ALIGNMENT);
        P2.add(paste);
       Container c=getContentPane();
        c.add(P2);
       //COPIES TEXT FROM FILE ON MY DISK TO THE TEXTAREA
       private class copyhandler implements ActionListener
       { public void actionPerformed(ActionEvent event)
         { JFileChooser fileChooser = new JFileChooser();
           fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY );
           int result = fileChooser.showOpenDialog(testing4.this);
           // user clicked Cancel button on dialog
           if ( result == JFileChooser.CANCEL_OPTION )
             return;
           fileName = fileChooser.getSelectedFile();
           if ( fileName == null ||
              fileName.getName().equals( "" ) )
           JOptionPane.showMessageDialog( null,"Invalid File Name",
                                            "Invalid File Name",
                                          JOptionPane.ERROR_MESSAGE );
           else
           { try
             { FileReader in = new FileReader(fileName);
               BufferedReader reading= new BufferedReader(in);
               String store="";
               while (reading.ready())
               { StringTokenizer st = new StringTokenizer(reading.readLine());
                 store=store+st.nextToken()+"\n";
               display.setText(store);
             catch ( IOException e )
             { JOptionPane.showMessageDialog( null,
                                          "Error Opening File", "Error",
                                          JOptionPane.ERROR_MESSAGE );
      public static void main (String [] args)
      { testing4 done =new testing4();
        JFrame frame = new JFrame("testing");
        frame.addWindowListener(new WindowAdapter()
                                 public void windowClosing(WindowEvent e)
                                   System.exit(0);
        done.init();
        frame.getContentPane().add(done);
        frame.pack();
        frame.setSize(205,110);
        frame.setVisible(true);
    }

    It Still giving a blank page.
    New Code
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    //import java.lang.Object;
    public class testing4 extends JApplet
    { private JTextArea display;
      private JScrollPane scrollPane2;
      private JButton paste;
      private JPanel P2;
      private File fileName;
      public void init()
        paste=new JButton("paste");
        paste.setMinimumSize(new Dimension(90,20));
        paste.setPreferredSize(new Dimension(90,20));
        paste.setMaximumSize(new Dimension(90,20));
        copyhandler pa=new copyhandler();
        paste.addActionListener(pa);
        display=new JTextArea();
        scrollPane2=new JScrollPane(display);
        scrollPane2.setVerticalScrollBarPolicy(
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane2.setMinimumSize(new Dimension(200,58));
        scrollPane2.setPreferredSize(new Dimension(200,58));
        scrollPane2.setMaximumSize(new Dimension(200,58));
        P2=new JPanel();
        P2.setMinimumSize(new Dimension(200,80));
        P2.setPreferredSize(new Dimension(200,80));
        P2.setMaximumSize(new Dimension(200,80));
        P2.setLayout(new BoxLayout(P2,BoxLayout.Y_AXIS));
        scrollPane2.setAlignmentX (Component.LEFT_ALIGNMENT);
        P2.add(scrollPane2);
        paste.setAlignmentX(Component.LEFT_ALIGNMENT);
        P2.add(paste);
       Container c=getContentPane();
        c.add(P2);
       //COPIES TEXT FROM FILE ON MY DISK TO THE TEXTAREA
       private class copyhandler implements ActionListener
       { public void actionPerformed(ActionEvent event)
         { JFileChooser fileChooser = new JFileChooser();
           fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY );
           int result = fileChooser.showOpenDialog(testing4.this);
           // user clicked Cancel button on dialog
           if ( result == JFileChooser.CANCEL_OPTION )
             return;
           fileName = fileChooser.getSelectedFile();
           if ( fileName == null ||
              fileName.getName().equals( "" ) )
           JOptionPane.showMessageDialog( null,"Invalid File Name",
                                            "Invalid File Name",
                                          JOptionPane.ERROR_MESSAGE );
           else
           { try
             { FileReader in = new FileReader(fileName);
               BufferedReader reading= new BufferedReader(in);
               String store="";
               while (reading.ready())
               { StringTokenizer st = new StringTokenizer(reading.readLine());
                 store=store+st.nextToken()+"\n";
               display.setText(store);
             catch ( IOException e )
             { JOptionPane.showMessageDialog( null,
                                          "Error Opening File", "Error",
                                          JOptionPane.ERROR_MESSAGE );
      public static void main (String [] args)
      { testing4 done =new testing4();
        //you did not set applet's width and height:
        //applet is a container too
        done.setWidth(205);
        done.setHeight(110);
        JFrame frame = new JFrame("testing");
        frame.addWindowListener(new WindowAdapter()
                                  public void windowClosing(WindowEvent e)
                                  { System.exit(0);
        done.init();
        frame.getContentPane().add(done);
        frame.pack();
        frame.setSize(205,110);
        frame.setVisible(true);
    }

Maybe you are looking for

  • Fork and BPM

    Hi I am using Fork in the BPM to collect and merge 3 messages. This is same as STD pattern "BpmPatternCollectMultiIf". It is working fine, it collects--> transforms --> sends. But always two PE are in "In process" state with a "clock" indicator. I tr

  • RE: Vendor Sales in Report

    We sell variants article created under generic article. The POS sales captured the variant articles. The articles belonging to which vendor is current maintain under Purchase info record. However, in the case of variant, the pricing is maintained usi

  • ESS and CATS available in ABAP webdynpro

    Hi Friends, Currently we are under ECC6.0 with the following SP13. SAP_BASIS     700     0013     SAPKB70013     SAP Basis Component SAP_ABA                     700     0013     SAPKA70013     Cross-Application Component And iam looking is the ESS an

  • Idoc to customer pi

    Hi everyone, As i am beginner want to understand the idoc from r/3 to customer pi and customer pi to scb pi in abap. And i even surf in net , i couldn't undrstand anythng. so guys,can anyone know the steps and example . pls let me know. [email protec

  • My 2009 MacBook Pro is slow to sleep - running mavericks - how do I fix?

    MacBook now takes 30-45 seconds to sleep and then wakes by itself later on.  Have checked for old printer q's and found none.  Operating wirelessly with new apple router off comcast cable modem.  Used to sleep immediately and stay until awakened.  An