Why Class.forName is used to load the driver ?

Hi all,
Why Class.forName() is used to load the driver ?. Can I use any other method to load the driver safely ?.
rgds
Antony Paul

That's still redundant. Sure, it works. Here are some equivalent forms:
    new MySqlDriver();
    DriverManager.registerDriver(new MySqlDriver());
    New LinkedList().add(new MySqlDriver());
    if (new MySqlDriver() == new MySqlDriver())
        System.out.println("department of redundancy department");
    Driver unusedVariable[] = new Driver[] { new MySqlDriver() };
    Class anotherUnusedVariable = MySqlDriver.class; // I'm not 100% sure this works
    new File(new MySqlDriver().toString());
    while (new MySqlDriver() == null)
    new Double(Math.sqrt(new MySqlDriver().toString().length()) / 42);

Similar Messages

  • Why is Class.forName( ) so useful?

    I still don't get why Class.forName so useful to java?
    If I do:
    Class c = Class.forName("dog");
    Dog d = c.newInstance();But what's wrong with:
    Dog d = new Dog();Why does java need that Class.forName thing? Can anyone give an counter example to demonstrate the case in my second way won't work?
    Thanks.

    cpthk wrote:
    I still don't get why Class.forName so useful to java?
    If I do:
    Class c = Class.forName("dog");
    Dog d = c.newInstance();But what's wrong with:
    Dog d = new Dog();Why does java need that Class.forName thing? Can anyone give an counter example to demonstrate the case in my second way won't work?
    System.out.println("Class to instantiate?");
    String className = scanner.nextLine();
    Class c = Class.forName(className);
    Object o = c.newInstance();Also, Class has a lot more methods besides just forName().

  • Why does my macbook pro stop loading the webpage every time i try to access netflix or youtube?

    Why does my macbook pro stop loading the webpage (in safari) every time I try to access netflix or youtube?

    Back up all data before proceeding.
    This procedure will unlock all your user files (not system files) and reset their ownership, permissions, and access controls to the default. If you've intentionally set special values for those attributes on any of your files, they will be reverted. In that case, either stop here, or be prepared to recreate the settings if necessary. Do so only after verifying that those settings didn't cause the problem. If none of this is meaningful to you, you don't need to worry about it, but you do need to follow the instructions below.
    Step 1
    If you have more than one user, and the one in question is not an administrator, then go to Step 2.
    Triple-click anywhere in the following line on this page to select it:
    sudo find ~ $TMPDIR.. -exec chflags -h nouchg,nouappnd,noschg,nosappnd {} + -exec chown -h $UID {} + -exec chmod +rw {} + -exec chmod -h -N {} + -type d -exec chmod -h +x {} + 2>&-
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window by pressing command-V. I've tested these instructions only with the Safari web browser. If you use another browser, you may have to press the return key after pasting.
    You'll be prompted for your login password, which won't be displayed when you type it. Type carefully and then press return. You may get a one-time warning to be careful. If you don’t have a login password, you’ll need to set one before you can run the command. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator.
    The command may take several minutes to run, depending on how many files you have. Wait for a new line ending in a dollar sign ($) to appear, then quit Terminal.
    Step 2 (optional)
    Take this step only if you have trouble with Step 1, if you prefer not to take it, or if it doesn't solve the problem.
    Start up in Recovery mode. When the OS X Utilities screen appears, select
              Utilities ▹ Terminal
    from the menu bar. A Terminal window will open. In that window, type this:
    res
    Press the tab key. The partial command you typed will automatically be completed to this:
    resetpassword
    Press return. A Reset Password window will open. You’re not going to reset a password.
    Select your startup volume ("Macintosh HD," unless you gave it a different name) if not already selected.
    Select your username from the menu labeled Select the user account if not already selected.
    Under Reset Home Directory Permissions and ACLs, click the Reset button.
    Select
               ▹ Restart
    from the menu bar.

  • Why do I have to continuall​y redown load the driver for my c6180 all in one printer every few months

    why do I have to continually redown load the driver for my c6180 all in one printer every few months

    Please read this post then provide some details.  What operating system? Are there any error messages on the printer or computer screen when printing fails?
    Running the diagnostics at http://www.hp.com/go/tools may help resolve the issue.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • Why is FCPX only using 1GB of the 16GB of memory I have available?

    Why is FCPX only using 1GB of the 16GB I have available?
    Any ideas?

    Hi
    latest version Yosemite
    latest version FCPX
    300gb of 500gb used
    just replaced optical drive with Samsung 840 EVO 500GB SSD which I'm now using as the main drive (also containing media).
    Media varies. 720p or 1080p.
    Its been awful for a while now.

  • Unable to load the driver???

    Hi,
    I am facing problem in loading the driver..
    Following is the set up..
    classpath=.;c:\;d:\Oracle\Ora81\jdbc\lib;
    Oracle client is installed on my machine. path is
    d:\Oracle\Ora81\jdbc\lib\classes111.zip;
    jdk installed is..
    c:\jdk1.2.2;
    I am trying to do this to load the driver     
    Class.forName("oracle.jdbc.driver.OracleDriver");
    program is compiling successfully, throwing the exception.
    "ClassNotFoundException"
    Can anyone tell me what is the problem . What else I need to do to load the driver
    Thanks in Advance

    Add the classes111.zip file to your env var CLASSPATH.
    Test this by running the following at the command line.
    java oracle.jdbc.driver.OracleDriver
    If you get a class not found error then your classpath is wrong. If you get a method not found (main) then your classpath is right. Do not run your application until this works.

  • I can't load the driver for a canon ir c2550.

    I can't load the driver for a canon ir c2550.  Installer gets to where it looks for the drive and never finds it.  Drive only has 18G of space left.  Help??
    I have an early 2008 MacBook Pro
    Thanks!!

    Thanks so much for your response
    I reset printer systems, and was only able to add Canon MG6200 series, either with Bonjour or Canon IJ Network, but cannot find the correct printer software for MG6250 (there is no option for any Canon MG printers) the only choice is Generic PostScript Printer.
    I have tried using this, but the print job is not going to the printer itself, it appears that it is, but then under the canon print box, it simply dissappears.
    Paul_31
    At this point is the printer connected to the Mac via a USB cable?
    Do you think that I should attach the printer with the old usb cable from my previous printer and try that appears to defeat the purpose of having a wifi printer    Or will this simply allow the computer to find the printer and then I can remove the cable?  Thanks

  • Why class.forName to load driver

    hi all,
    as most of the times the loading of jdbc driver is carried out
    by using the function class.forName, Why so ?
    as i tryied with creating the object of the driver class like
    Object driver = new <JDBC DRIVER>;and the code worked fine
    so is there any difference in the two methods of loading the
    drivers ?
    if not wot is the use of method class.forname ?
    thanx

    That 's fine, but what if you change database back end in near future.
    I will define a property and used class.forName ("read property").
    In your case, you have to change the code about loading the JDBC driver as well.
    Using std. JDBC API functionality and loading driver dynamically, leaves some of the part of the code that are not a candidate for a change in case back-end DB is changed.
    BS

  • Why Class.forName?...

    I'm trying to understand the use of Class.forName in JDBC programing. �What is the really goal for this class?
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch(ClassNotFoundException ex){
    // something
    Regards.

    I'm trying to understand the use of Class.forName in
    JDBC programing. �What is the really goal for this
    class?There are two implied questions...
    -What does it do?
    1. The class is loaded. All classes are loaded this way but normally the compiler does the work for you.
    2. When a class is loaded, if there are any 'static initializers' in the class then those are run. Again true for any class when it is loaded.
    3. JDBC drivers have a static initializer which registers the driver with the JDBC driver manager. See the DriverManager.registerDriver(Driver driver) method and the JDBC spec for more specific info.
    -Why it is done this way?
    As a guess because the original JDBC implementor(s) just found out about static initializers and thought they were 'cool'. It would be just as easy and more meaningful to do it using a different methodology.

  • Why Class.forName("driver class") ?

    Hi,
    whay we are using Class.forName("driver class"). why we dont import the driver package and access the required classes and methods?
    for eg:
    insead of calling
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); ,can we use import com.microsoft.jdbc.sqlserver.*; ?
    what is the use of DriverManager in this context? any connection between DriverManager and Class.forName() ?
    expecting answers.

    sure you can import the packages and use the classes directly but that defeats the whole purpose of pluggable drivers.
    Class.forName causes the class to be loaded and as stated before that should cause the driver to register itself with the driver manager.
    so then if you have a system where you are talking to several different database vendors then you don't have to worry about which is which as the DriverManager handles it for you.
    the big pros that i have actually seen though for having this be pluggable and not hard-coded (with the exception of the URL although you can do this dynamically as well) is what happens if you switch databases. if you import the package and use fully named classes and you switch databases at some point (could be just an upgrade of the same vendor's database) you are screwed.
    same problem could happen if you switch drivers for some reason.
    at any rate if you use things properly and are careful then you should only ever have to change your URL the rest of the code is fine if you use the DriverManager and use the drivers dynamically otherwise...

  • Why can i NOT use "differential" on the MAX test panel for channels 8-16??

    I have a USB-6218
    This is a 32 channel device with 16 Differential inputs.
    Why can't i use the MAX test panel to view any channel beyond AI-7 using the Differential setting? It shades out differential even though my device has this capability.
    WHY???? 

    I am using MAX 4.1.0.3001 in conjunction with LV 8.0 and the USB-6218.
    I go to MAX, Expand devices, expand MX devices, Right click on the USB-6218 (device2), and go to the test panels.
    From there i am unable to view any differential pair beyond 8.
    How am i supposed to Thru-Calibrate my equipment? Generally to achieve a valid calibration i use MAX itself to record the raw voltages the board "sees" as i apply known loads to the sensors.
    The reason i need to check all this out is because DIFF pairs > 8 also are not working in my VI! Im am not sure if this is related or not.

  • Why is XP COM port complaining it cant load the driver (Error31)

    Uninstallation of all NI software and reinstallation of the V1.6 upgrade results in COM3 and COM4 visible in XP Device Manager at the usual addresses and sharing IRQ 7 with an ! over them.
    The first port complains "This device is not working properly because Windows cannot load the drivers required for this device. (Code 31)". The second port complains "Windows cannot load the device driver for this hardware because a previous instance of the device driver is still in memory. (Code 38)"
    Using the NI software to test the ports the software and hardware are ticked off but COM3 and COM4 are not shown ... help!!!
    Attachments:
    NIBadComPorts.bmp ‏862 KB

    Try right-clicking on both devices in the Windows Device Manager and select uninstall. Then open Measurment and Automation Explorer (MAX) and go-to Tools->NI-Serial-> Recover Unused Serial Ports. Hopefully, this will get your system back to a safe state. Then, just reboot your computer.
    I hope this helps out.
    -JoshuaP

  • Using JNIWrapper load the Library

    Hi,
    I am using JNIwrapper , i want to load the dll(usb4xx) . I write the code and copied all JNIWrapper jar files and Pasted to \jre\lib\ext\.
    Now my program compiled. but in runtime it throws exception.
    My Error Message is
    Exception in thread "main" java.lang.NoClassDefFoundError: com/jniwrapper/n (wrong name: com/jniwrapper/N)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at com.jniwrapper.Parameter.<clinit>(SourceFile:22)
    at CrossMatch.<init>(CrossMatch.java:38)
    at CrossMatch.main(CrossMatch.java:189)
    Anyone knows please tell me.
    Regards
    devi

    Hello and thank you very much for your attention ,I examined
    both of the way you recommended me ( setting ascb in the
    actionscript preferences , and either put the ascb folder next to
    the movies .fla file ,but the I encounter the following errors:
    1120: Access of undefined property pen.
    1120: Access of undefined property pen.
    5001: The name of package 'ascb.drawing' does not reflect the
    location of this file. Please change the package definition's name
    inside this file, or move the file. C:\ascb\drawing\Pen.as
    would you please help me ,sincerely yours Mohsena

  • Why can't I use Roboform with the new version?

    You keep asking me to upgrade to the new firefox, but it does not use Roboform. Why can't I use roboform? Without Roboform, I can't use Firefox!

    Firefox says to update to 6.0 but roboform will not work. Should I update to firefox 6.0 or not?

  • Why can I not use commas in the Author part? They change into semicolons!

    I'm just a simple user, not a technician, but you probably are!
    Why is it that in CS2 XMP sees the usage of a comma, in the File Info Author field, as a fieldseparator and changes it into a semicolon?
    Whilst it does not change the comma in the Author Title!
    Since the early versions of Photoshop we fill the Author field (iptc 80) with the name of the photographer like Name, Surname.
    Our photomanagement system uses iptc 80 (byline) as photographer field but only shows Name now, instead of Name, Surname.
    Anyone of you can explain why we can't use a comma anymore? and when we use a comma it changes into a semicolon.
    I should expect that using a semicolon would act as field separator....
    Thanks in advance,
    [email protected]

    Are any of you going to the Adobe Developer Conference scheduled to be held for plugin providers at San Jose on Nov 7/8?

Maybe you are looking for

  • Delivery service level

    Hi, I need a report concerning our Delivery service level (vendor self evaluation). Somebody knows if there is a standard report?. The report must contain sales order with quantities, dates, sku, and its respective delivery with quantities and dates.

  • Not able to see more than one period in DRP Planning Book

    Hi Where do we set the no of periods( days, weeks etc) that should be visbile in the DRP planning book in the SAP SPP. Also we are getting invalid periodicity in this planning book, when we select one of the available timebucked profile ids. Any clue

  • What is fault message type in mapping

    hi folks,             what is the use of fault message type in message mapping . where do we use them .please spare a little time to type rather to refer to  other blogs. have a nice day

  • Java.io.IOException: The specified procedure could not be found

    I get this error in this code. private boolean updateCICServer(){ boolean updatestatus=true; long fsize=0; int arraysize=0; byte temp[]; try{ if(f.length()>this.m_iCICDataSize){ if(DEBUG) System.err.println("update file"); fsize = f.length(); arraysi

  • 16:9 Widescreen

    I've got a 16:9 widesreen DV file extracted using Mpeg Streamclip. When played in Logic it's 4:3, is there anyway to get Logic to spit out 16:9?..... film directors can get really picky when their little babies get all squished up!!