Value of Statement becomes null even when the connection is open

my small program deals with jdbc during which i met with this strange situation.
i want the value assigned to an instance of Statement (say 'st') for future use. So i declared st' as a class variable. and the variable is assigned with a value inside try-catch block which is inside the constructor. But when i tried to access it from outside it seems to be null. i ve made it clear by giving two print statements INSIDE and OUTSIDE the try-catch block. More over u can notice that the
value of an integer variable remains unaltered INSIDE and OUTSIDE the try-catch block. Wats wrong with my coding? Is there anything
special regarding the 'st' variable which is a reference of Statement interface. BUT WHEN THE DATABASE WAS MS Access, THE
VALUE OF 'st' WAS EXACTLY THE SAME INSIDE AND OUTSIDE THE try-catch BLOCK(i tried it also by making appropriate changes in the jdbc part).
the output in both the situation is copied here.
please correct me.......any help welcomed.
my program
import java.sql.*;
public class MyStatement
     Connection con;
     Statement st;
     ResultSet rs;
     int test=0;
public MyStatement()
try
                         Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "passes");
Statement st = conn.createStatement();
test=111;
System.out.println("value of statement INSIDE try-catch block: "+st);
System.out.println("value of test INSIDE try-catch block: "+test);
catch (Exception e){System.out.println("sql "+e);}
System.out.println("value of statement OUTSIDE try-catch block: "+st);
System.out.println("value of test OUTSIDE try-catch block: "+test);
public static void main(String args[])
new MyStatement();
}

Try this:
public class MyStatement {
    Connection conn;
    Statement st;
    ResultSet rs;
    int test = 0;
    public MyStatement() {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "passes");
            st = conn.createStatement();
            test = 111;
            System.out.println("value of statement INSIDE try-catch block: " + st);
            System.out.println("value of test INSIDE try-catch block: " + test);
        } catch (Exception e) {
            System.out.println("sql " + e);
        System.out.println("value of statement OUTSIDE try-catch block: " + st);
        System.out.println("value of test OUTSIDE try-catch block: " + test);
    public static void main(String[] args) {
        new MyStatement();
}

Similar Messages

  • Help! iWeb won't open properly after I updated to Yosemite. No old websites, no workspace- nothing is displayed even when the app is open. HELP!

    Help! iWeb won't open properly after I updated to Yosemite. No old websites, no workspace- nothing is displayed even when the app is open. HELP!

    To open your domain file in Lion, Mountain Lion or Mavericks or to switch between multiple domain files Cyclosaurus has provided us with the following script that you can make into an Applescript application with AppleScript Editor. Open Script Editor, copy and paste the script below into Script Editor's window and save as an application.
    do shell script"/usr/bin/defaults write com.apple.iWeb iWebDefaultsDocumentPath -boolean no"
    delay 1
    tell application "iWeb" to activate
    You can download an already compiled version with this link: iWeb Switch Domain. Note:  you may have to Control (right) - click on the app after uncompressing and select Open due to the Sandboxing feature of OS X.  If you have problems with the app create your own with AppleScript Editor.
    Just launch the application, find and select the domain file in your Home/Library/Application Support/iWeb folder that you want to open and it will open with iWeb. It modifies the iWeb preference file each time it's launched so one can switch between domain files.
    WARNING: iWeb Switch Domain will overwrite an existing Domain.sites2 file if you select to create a new domain in the same folder.  So rename your domain files once they've been created to something other than the default name.
    NOTE: In Lion and Mountain Lion the Home/Library folder is now invisible. To make it permanently visible in Lion or Mt. Lion enter the following in the Terminal application window: chflags nohidden ~/Library and press the Return key - 10.7: Un-hide the User Library folder.
    For Mavericks and Yosemite go to your Home folder and use the View ➙ Show View Options menu to bring the this window:

  • My macbook wakes up and then goes back to standy even when the lid is open.

    so my macbook turns on and then the screen stays on for like 2 seconds then goes back to standby. it does not shut down because when i wake it up again by pressning any button, it is where i was before. Also when it is in standy even when the lid is on, the standby light blinks as if the lid is closed. i can never use it because the screen only stays on for 2 seconds then turns off going to stand by. does anyone have a similar problem or know how to fix this?
    thanks in advance!

    mkedge wrote:
    it worked for snow leopard.
    now, in Lion, when you open the lid, it automatically detects that you opened and it turns on macbooks display
    That's called progress!

  • Save as does not Create PDF Compatible File even when the creare pdf compatible files is on, Illustrator CC 2014

    save as does not Create PDF Compatible File even when the creare pdf compatible files is on, Illustrator CC 2014

    When I open is adobe acrobat I get this message.
    "This is an Adobe® Illustrator® File that was
    saved without PDF Content.
    To Place or open this  le in other
    applications, it should be re-saved from
    Adobe Illustrator with the "Create PDF
    Compatible File" option turned on. This
    option is in the Illustrator Native Format
    Options dialog box, which appears when
    saving an Adobe Illustrator  le using the
    Save As command."

  • Credit exposure updating even when the sales order is blocked

    Hi,
    We are using FSCM credit management. We observed that the credit exposure is updated even when the sales order is blocked. When we investigated it is found out that SD has removed the requirement 101 in the subsequent functions. The reason is they want the confirmed quantity to be updated even though the order is blocked. This will allow the Material Planning to go ahead and purchase the goods. Is there a way around it where we can have MM see the confirmed quantity in the order and it will not updated the credit exposure?
    Thanks and Regards
    Madhu Vutukuri

    Hi Sravan,
    Please let us know, whether the document is really getting reflected in the blocked documents list for a particular kind of block and you are releasing that particular block in the specified area as we have different areas for releasing blocks. Chances are that in the mean time, the concerned block might have been removed in the system and not updated as it might have been. It will be of great help, if you can provide us with the screenshots of the process followed.
    Regards,
    Aman

  • HT4437 hi even when i connect my macbook and apple tv to the same wifi network i cant put on the air play mirroring option.my airplay mirroring option does not detect any device.what can i do for this?

    hi even when i connect my macbook and apple tv to the same wifi network i cant put on the air play mirroring option.my airplay mirroring option does not detect any device.what can i do for this?

    See
    http://support.apple.com/kb/TS4215

  • How do I stop all of my music in my itunes library syncing to my iphone 5 even when the songs aren't ticked?

    How do I stop all of my music in my itunes library syncing to my iphone 5 even when the songs aren't ticked?

    The frustrating part about the restore is that is seems to be finished when it in fact is not.  The restore will look "finish" and your phone will be at the Swipe to Unlock screen. If you swipe and look at your home screen at this point of the restore, you'll see everything is not quite right.  While the process seems to be not doing anything just leave the phone attached and do something else for about an hour.  This part of the process is not mentioned during the restore operation.  I believe there are about two steps to the restore process: 1) restore the phone settings (ringtones, background, notification settings, etc.) and give the user the unlock screen; 2) without letting the user know there is still more to do, begin the slow process of restoring all the music, movies, apps and what not.  It's this second step that causes the confusion.  Nothing lets you know to wait that process out.  I've restored a couple devices from a computer backup and the 2-step process looks the same.

  • How do I  undo an update to pages 2.1 on an iPad 2? I can no longer open a document previously saved, even when I try to open it in the iCloud and on my Mac.

    How do I  undo an update to pages 2.1 on an iPad 2? I can no longer open a document previously saved, even when I try to open it in the iCloud and on my Mac.

    With IOS Pages v2.0 and v2.1, Apple introduced a new document format that is incompatible with prior Pages versions on IOS or OS X Pages ’09. Opening older documents with these recent versions of Pages will permanently prevent the document from opening in earlier versions of Pages on IOS or OS X.
    Nice of Apple to warn people.
    There is no undo of an iTunes application update, short of forcing iTunes to restore IOS v6 back on that iPad 2. Even if you did that, you won't find the IOS Pages v1.7.2 in the iTunes store now.
    IOS Pages v2+ will allow you to export content in Word .docx format. You do this by first tapping the box with an up-arrow in it (next to the left-most +). A menu will slide up — choose Send a Copy. Select a document icon. Pick Mail, and then Word. Your Pages v2.1 document will now be converted to Word .docx, and attached to an email body. Fill in the to address and send.

  • Ipod touch is not syncronizing is not even on the list of devices on itunes even when I connect it, is not syncronizing wireless either HELP

    ipod touch is not syncronizing is not even on the list of devices on itunes even when I connect it, is not syncronizing wireless either HELP
    I have some updates in regards my music that I want to upload to mi ipod touch 4th generation 64gb and my computer recognizes the IPOD connected via usb but my computer on  itunes doesnt have any info about it, I don't want to reset all the settings becuase I spent a lot of money on you guys and simply mi ipod is not syncronizing I DEMAND help please also my ipod is not syncronizing wifi it says: "syncronization will be done when VAIO (my laptop) is available" but my computer  IS AVAILABLE WHAT IS WRONG WITH THIS DEVICE someone better get me a resolution this is a huge inconvenience. I am going to stop puchasing apps and music if this is not resolved I DON'T want this tutorial http://www.apple.com/la/support/ipodtouch/assistant/itunes/ or this http://support.apple.com/kb/HT1808 those are not even close to the new update Apple did to ITunes

    This will help: http://support.apple.com/kb/HT1212 : iPhone, iPad, iPod touch: Wrong passcode results in red disabled screen

  • It has been only about a month that i bought my macbook pro 15 but it is heating up really fast on the left side even when the cpu usage is only 10%...i'm worried if this is a problem of the hardware.

    it has been only about a month that i bought my macbook pro 15 but it is heating up really fast on the left side even when the cpu usage is only 10%...i'm worried if this is a problem of the hardware?

    The way something "feels" is very subjective.  We would need to know your actual temps.  You can install the free iStat Pro widget which is available as a download directly from Apple:
    http://www.apple.com/downloads/dashboard/status/istatpro.html
    Let us know what CPU temps you're seeing at the time you feel your machine is hot.  As you indicated your CPU usage was only 10%, that would imply that you already know that heavy CPU usage would be one cause for your machine to be running on the warm side... but that doesn't seem to be the cause here.

  • Hi, how can I keep the same zoom level for all the pages I view in Safari and even when I close and open it.  Indeed with a 27 inch Imac I have a lot of space, most of the websites are built for smaller resolutions  and my sight is dropping !   Thx

    Hi, how can I keep the same zoom level for all the pages I view in Safari and even when I close and open it.  Indeed with a 27 inch Imac I have a lot of space, most of the websites are built for smaller resolutions  and my sight is dropping !   Thx

    Hi, how can I keep the same zoom level for all the pages I view in Safari and even when I close and open it.  Indeed with a 27 inch Imac I have a lot of space, most of the websites are built for smaller resolutions  and my sight is dropping !   Thx

  • My iphone 4s got water in the headphone port. I put my phone in rice for 24 hours and the LED light is on. It stays on even when the phone is off. How can I fix it with out spending 200 bucks at apple to have them fix it?

    My iphone 4s got water in the headphone poert. I put my phone in rice for 24 hours and the LED is on. It stays on even when the phone is off. How can i fix it without taking it to apple and spendding 200 dollars to have them fix it?

    Short answer is you probably cannot.  Once water gets inside the device and it is powered on, the damage likely is permanant. 

  • MacBook pro will not charge even when the charger is plugged in and working

    So this is a strange one.
    I have been using my MacBook pro for a lot of film editing and motion graphics. Recently, I noticed that my battery kept going down, even when charging. I thought nothing on it and kept using it. After around 4 hours, the battery went from 90% to 23% WHILE plugged in. This got me nervous. When I plug in the MagSafe charger, the light comes on and I get the "charging" symbol in my toolbar. The light turns orange and then, after a few minutes, the power starts to go down instead of up.
    I have had this laptop since Christmas 2012 and this has never happened before. The laptop does charge, but only when I am running no application, when the screen is shut or when the laptop is powered off. Bear in mind that right now, I am on Firefox, that is the only application open, yet the charge is still going down. I assumed it was because I was using Premiere CS6, After Effects CS6 and Cinema4D, but now even when they are not open, the batter will not charge when I am using the laptop.
    What is going on? Is in the charger? Any help would be greatly appreciated and I am starting to stress!
    Thank you everyone for reading,
    -Rory Campbell
    UPDATE: I am currently only running Firefox and Finder. Now the laptop is charging as usual. However the second I open up Premiere, After Effects etc, it goes down. I have no idea what is going on!

    Try resetting the PRAM and SMC. If you don't know how to, don't worry. They're very easy to reset. Just google how to do it. If that doesn't work, the only thing I would suggest is to take both the laptop and the charger to your local genius bar to have them examined. If it's less than a year old, apple should replace whatever is wrong with it as long as it was a factory defect.

  • My 4s continues to lose wi-fi and reverts to 3G even when the phone is 4 ft from the router.

    My 4s continues to lose wi-fi and reverts to 3G even when the phone is 4 ft from the router. Is this a defect in my phone? It happens when I am home and I switch to my wi-fi. It doesn't matter where the phone is in relation to the router. Please note, I have my phone set to NOT sleep. Does any one know why my phone reverts to 3G? I have to manually set it to wi-fi every time this happens.

    I have the same issue with my iPhone 4s. It was not an issue when I was using iOS5, but it started once I upgraded to iOS6 and the recent update of iOS6.0.1 did not fix it. Judging from the release notes, Apple thinks this is only an iPhone 5 issue, as they say they fixed it for iPhone 5's.
    I have an iPad 2 (iOS6.0.1) and a 3rd generation iPod touch (latest iOS5 release), as well as an Apple TV 2. None of the other devices have this problem and they are all on the same network.
    Something interesting... my iPhone 4s works fine on the wifi where I work. At home, it continually turns on and off. My home network is using a Netgear router (WNDR3400) and the iPhone is connecting to it using WPA2+PSK protocol. Hopefully, this information can help Apple figure out the problem.
    (I remember my iPod Touch having a similar issue a few years ago with iOS 4, when I had a different Netgear router using the same security protocol. I think iOS 5 fixed it for the iPod Touch... I wonder if some Apple products have an issue with Netgear Routers using that encryption.)

  • Is it true that music pauses when a phone call comes in even when the ios6 'do not disturb' feature is activated?

    is it true that music pauses when a phone call comes in even when the 'do not disturb' feature is activated?
    thanks in advance

    You could test it out and let us know!
    Best of luck.

Maybe you are looking for

  • Spell check not working on my 2 Win 7 64 bit computers; option set

    I have Firefox 4.01 on my two Windows 7 64bit computers. One has the professional version. I have Spell Check selected in the options menu Advanced, General tab. Pierce

  • Video centre on N95 rocks!

    Some of the new features on N95 are really cool.the video centre in applications has links to you tube, reuters etc with crystal clear videos,hope the future DVB-H based TV services have the same clarity

  • TS2529 I can't activation my iphone

    I Pay this iphone from allegro poland when I update it sind this massig Please help more then100 day I wait no help from AT&T ore apple group?

  • My ipad doesn't turn on

    i have an ipad3 about 6months but before few days it stopped working. it doesnt open and the battery doesnt working..... any idea? i tried to set it on dfu mode but nothing!!!!

  • Business content-Personnel Cost Planning

    Hi, expert Now, our clients work in HR dept. wants to do personnel cost planning in BW side. 1) is there any standard business content for Personnel Cost Planning in SAP? 2) and if we have how to active these required BCT. 3) Does SAP have 'personnel