What is happening in the code

What is happening here:
Class.forName("com.mysql.jdbc.Driver").newInstance();
I use it and it works fine but I have no idea what is going on there?

Class.forName() loads the given class. In itself, that isn't interesting. The beef lies in that loading a class executes any static blocks in that class.
If you had the source to com.mysql.jdbc.Driver, it would probably start something like:
public class Driver
    static {
        Driver driver_object = new Driver();
        java.sql.DriverManager.registerDriver(driver_object);
}The static block does the actual work of registering the driver. Class.forName() is really just a bit of a hack to get that static block executed.
The newInstance() call is customary because there is an old rumor that some buggy JDBC driver somewhere is missing the static block, and has the registerDriver() call in a Driver() object constructor instead. A belt and suspenders kind of thing.

Similar Messages

  • What will happen with the code?

    What will happen with the code below?
    for (i=0; i<=10000; i++)
    Object[] obj = new Object[5];
    In every loop, a new Array of Object wll be created. Will the Array of Object created in the
    current loop( for example, i=2001), eliminate the Array of Object created in previous loop
    (for example, i=2000 or 1999)? How the memory is allocated in every loop?
    Thanks.

    Each time through the loop, an array of five Object references is created. A reference to this array is assigned to the reference variable obj, causing the previously allocated array to be unreachable (except the first time through the loop, if obj was originally null). The garbage collector will collect these unreachable arrays if the memory gets low.

  • What is happening in the most recent keynote when I click on a slide and it pulses (larger-smaller)  Two of my slides have disappeared in the navigator although if I play through them they are there.

    What is happening in the most recent keynote when I click on a slide and it pulses (larger-smaller)  Two of my slides have disappeared in the navigator although if I play through them they are there and the slides have their orignal number--there are just white spaces where the slide should be and I can only get to the slide by clicking through from the prior slide.  How do I get the sldies back into the navigator so I can see them.  Oddly, they are show up just find on the light table. 

    Try removing any transitions or builds on these slides, or delete the slides then recreate them as fresh slides.
    There are many playback anomalies in Keynote 6 which Apple have said they will be  sorting out next year.

  • What will happen to the stuff in my keychain after today? I don't want iCloud. Can I keep the keychain? in my system?

    what will happen to the stuff in my keychain after today? I don't want iCloud. Can I keep the keychain in my system under lion? Can someone please help me?

    Thank you Sig. Well I keep all my passwords in my keychain. I'm concerned I'll lose them after today. I understand that keychain will be obsolete after today. I don't want icloud either, because I don't want all my personal info on a server. I want to keep my personal information in my system. Am I making any sense? Can you make any suggestions or offer any insights around this? 

  • What will happened in the excise while we sent free goods @ samples

    what will happened in the excise while we sent free goods @ samples

    Dear maha,
    What ever the Transactions(Except Exports)..you have to pay the Excise duty and Cess.
    Regards
    Luckky

  • What's wrong with the code?

    public void run()
    try
    {     for(;;)
         mgr = (RTPManager)RTPManager.newInstance();
         mgr.addSessionListener(this);
         mgr.addReceiveStreamListener(this);
         try{  /*****port1 = port2 = 29261, which port is only used in here
         localAddr = new SessionAddress(InetAddress.getLocalHost(), port1);
         destAddr = new SessionAddress(ipAddr, port2);
         }catch(Exception e)
              System.out.println(e + " 4");
         try{
         mgr.initialize(localAddr);
         }catch(Exception e)
         System.out.println(e + " 5");
         //set buffer
         bc = (BufferControl)mgr.getControl("javax.media.control.BufferControl");
         if (bc != null)
         bc.setBufferLength(20);
         try{
              mgr.addTarget(destAddr);
         }catch(Exception e)
         System.out.println(e + " 2");
    catch(Exception e)
         System.out.println(e+ " 3");
    the error when i run the code is like that:
    javax.media.rtp.InvalidSessionAddressException: Can't open local data port: 29261
    5
    java.io.IOException: Address already in use: Cannot bind 2
    which means there is error in :
    mgr.initialize(localAddr);
    mgr.addTarget(destAddr);
    But i don't know what's wrong with the code,
    can any one help me?

    I do not find any problem using the same ports for local and destination address with several unicasts. My problems are others.
    But note that the error is even at constructing the localAddress, I mean before trying the destinationAddress. Thus the reason cannot be the former is already in use. In fact I think the later belongs to a remote hosts. Likely, it is trying to access the destinationAddress through the localAddress, but this has not been constructed properly.

  • What will happen to " the new iPad " I bought 2 months ego. Now the model is discontinued . What apple will do?....really disappointing.

    What will happen to " the new iPad " I bought 2 months ego. Now the model is discontinued . What apple will do?....really disappointing.

    I just bought two new iPads a few weeks ago. If they're still in the return window they're going back. Maybe it's time to look at some of the Android tablets since all of a sudden Apple thinks the mini is a great idea.

  • What has happened to the iPad 2 finger select and drag technique? Since upgrading to iOS7 it does not work? I used this all the time to select multple images, approx 75  from an SD card containing 1000  images. Its painful indvidually selecting the images

    What has happened to the iPad 2 finger select and drag technique?
    Since upgrading to iOS7 it does not work?
    I used this all the time to select multple images, approx 75  from an SD card containing 1000  images. Its painful indvidually selecting the images

    What would you like us to tell you? If it doesn't work, there is nothing that we users can do about it.
    Please submit your feature request to Apple at this link: http://www.apple.com/feedback

  • Red highlight next to code in dreamweaver. What is wrong with the code and is it affecting the websi

    What is wrong with the code and is it affecting the website?

    Line 107 looks dodgy to me and it won't have any effect on your code.  However, it is a good idea to post a complete link to your CSS for us to see it in full and to validate it using external tools.  In fact, you could validate the CSS (and HTML) yourself..
    <http://jigsaw.w3.org/css-validator/>
    Good luck.

  • I'm trying to add the system date with a Label. What is wrong with the code

    import java.util.*;
    import javax.swing.*;
    public class CurrentDateApplet extends JApplet
         Calendar currentCalendar = Calendar.getInstance();
         JLabel dateLabel = new JLabel();
         JPanel mainPanel = new JPanel();
         int dayInteger = currentCalendar.get(Calendar.DATE);
         int monthInteger = currentCalendar.get(Calendar.MONTH)+1;
         int yearInteger = currentCalendar.get(Calendar.YEAR);
         public void init()
              mainPanel.add(dateLabel);
              setContentPane(mainPanel);
              dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
                        (Calendar.MINUTE);
    }

    As for what's wrong with the code, it would be easier if you said: it doesn't show the date (it does this instead), it doesn't compile (I get this message) etc.
    Anyway I'll assume you want to display the time in a label...
    dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
    (Calendar.MINUTE);This won't compile: the parentheses are mismatched, and there is simply no such thing as append(). So we could trydateLabel.setText("" + currentCalendar.get(Calendar.HOUR) + currentCalendar.get(Calendar.MINUTE));This wroks, but looks pretty nasty and it's not how you are supposed to format dates and times. Here's the unofficial party line, nicked from one of jverd's posts:
    Calculating Java dates: Take the time to learn how to create and use dates
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format
    From those links you should be able to find those applicable to times like this: http://www.exampledepot.com/egs/java.text/FormatTime.html
    Using this approach you would end up with something like:import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CurrentDateApplet extends JApplet
        private Date date;
        private JLabel timeLabel;
        private JPanel mainPanel;
        public void init()
            mainPanel = new JPanel();
            timeLabel = new JLabel();
            mainPanel.add(timeLabel);
            setContentPane(mainPanel);
            date = new Date();
            Format formatter = new SimpleDateFormat("HH:ss a");
            timeLabel.setText(formatter.format(date));
    }

  • If I take my bank card details off my itunes account and opened a new itunes account what would happen to the old account?

    If I take my bank card details off my itunes account and opened a new itunes account what would happen to the old account?

    you're more likely to get quick and accurate answers to an iTunes question in the iTunes forum, this is the GarageBand forum

  • If I take my bank card details off my itunes account and open a new itunes account what will happen to the old account?

    If I take my bank card details off my itunes account and open a new itunes account what will happen to the old account?

    you're more likely to get quick and accurate answers to an iTunes question in the iTunes forum, this is the GarageBand forum

  • What is happen when the screen goes white

    what is happen when the ipod screen is going blank

    what is happen when the ipod screen is going blank

  • What will happen to the data I´ve in my Key ring when migrating to iCloud

    What will happen to the data I´ve in my Key ring when migrating to iCloud?
    Any feedback is appreciated
    Uwe

    Hi Winston!
    Thanks for your quick response. I meant keychain items. So I you anserwed my question, perfectly.
    Best
    Uwe

  • What is happening to the pictures sent with text messages?

    What is happening to the pictures sent with text messages?

    We don't know unless you give us a little more detail as to what the problem is.

Maybe you are looking for

  • How do I import AVI video with stereo audio (and keep it that way)?

    Today I just discovered that all the AVI video with stereo audio I've ever imported into a Premiere Pro CS6 project has been mysteriously converted to mono. And I can't find any import setting anywhere that enable me to change this. Here's the deal..

  • Changing Links in Header Menu

    Hello, I was wondering what the best way is to modify the menu in the header of the portal. We would like to remove the "Mobile Devices" link and add in a "Reset Desktop" link. We are using the sampleportal with the JSPTabContainer as the default cha

  • UITableView re-order but not remove?

    Hi!, I'm trying to make a UITableView that will have a re-order functionality but not delete. I've implementer the - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath; AND - (void)tableView:(UITableView *)tableVi

  • Text File to Xml

    Hi, How to skip headers in text file through graphical message mapping..i put some condition but instead of that headers structures are created in output xml file. I need to eliminate that structure created in output xml file..Also headers is coming

  • OutputLabel and line breaks doesn't work - Is there a hack for JSF1.2?

    Hello, I use JSF 1.2 and Facelets to generate a form automatically. This works so far well. But if I have a label with line breaks, JSF does not convert the line breaks into � � tags. Is there a hack to convert line breaks into � � tags? A little exa