JVM optimization of load driver forName and db getConnection

I am working on a site that already had these jsp pages. There is very little java code to the site.
Almost everything is done through the jsp page plus one main java class to store state data.
The site's jsp page may do up to 7 queries on the database. On each query, the statements are these:
Driver DriverDB = (Driver)Class.forName(db_DRIVER).newInstance();
Connection ConnDB = DriverManager.getConnection(db_STRING,db_USERNAME,db_PASSWORD);
PreparedStatement StatementDB = ConnDB.prepareStatement("SELECT * from table");
ResultSet resultDB = StatementDB.executeQuery();My 2 questions are:
Does the forName call to load the driver get optimized out? Clearly the driver need only load once.
Does the getConnection reuse the same connection that was done in the previous call on the page?
There are some performance problems and I'm wondering if I should try to clean the code up or if the jvm
does it for me through optimization. It's running on Tomcat 5.5.x. and JVM 5.x.
Thanks for any insight.

import java.sql.*;
public class MyJDBC{
     public MyJDBC(){
     public static void main(String args[]){
          System.out.println("Testing JDBC COnnection...");
          try{
               Class.forName("com.mysql.jdbc.Driver").newInstance()
               java.sql.Connection conn;
conn =
=
DriverManager.getConnection("jdbc:mysql://localhost/bh
c?user=dave&password=dave");
          } catch(Exception e){
               System.out.println("Error" + e.toString());
}Try this when you initialize your connection (conn) :
Connection conn;
conn = Drivermanager.getConnection(
"jdbc:mysql://localhost/blc",
"dave", // username
"dave" // password
but still include everything else... I think it may just be a problem with your formatting.

Similar Messages

  • 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

  • Exception in thread "main" related to CLASSPATH and unable to load driver??

    Hi,
    I am a JAVA beginner, I have met some problems cannot solve, can somebody help?
    My OS is Windows2000
    Java SDK in C:\j2sdk-1_4_2_04 and Java JRE in C:\Program Files\Java\j2re1.4.2_04 [Installation: j2sdk-1_4_2_04-windows-i586-p.exe]
    MySQL in C:\mysql [Installation: mysql-4.0.18-win.zip]
    MyODBC in C:\Download\MYODBC [Installation: MyODBC-3.51.06.exe]
    MyJDBC in C:\mysql-connector-java-3.0.11-stable [Installation: mysql-connector-java-3.0.11-stable.zip]
    Enviornment Variables Settings
    PATH = C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\j2sdk1.4.2_04\bin;C:\mysql\bin
    JAVA_HOME = C:\j2sdk1.4.2_04
    (CASE ONE) - While I didn't set a new Enviornment Variable for CLASSPATH
    HelloWorld.class can work properly and LoadDriver.class cannot work due to Unable to load Driver (As below)
    C:\JavaTry>javac HelloWorld.java
    C:\JavaTry>java HelloWorld
    Hello World!
    C:\JavaTry>javac LoadDriver.java
    C:\JavaTry>java LoadDriver
    Unable to load driver.
    java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
    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 java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at LoadDriver.main(LoadDriver.java:7)
    (CASE TWO) - While I set a new Enviornment Variable for CLASSPATH (No matter which settings as below)
    CLASSPATH = C:\mysql-connector-java-3.0.11-stable\mysql-connector-java-3.0.11-stable-bin.jar
    CLASSPATH = C:\mysql-connector-java-3.0.11-stable
    CLASSPATH = C:\mysql-connector-java-3.0.11-stable\com;C:\mysql-connector-java-3.0.11-stable\org
    Both the HelloWorld.class and LoadDriver cannot work properly due to Exception in thread "main" java.lang.NoClassDefFoundError (As below)
    C:\JavaTry>javac HelloWorld.java
    C:\JavaTry>java HelloWorld
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
    C:\JavaTry>javac LoadDriver.java
    C:\JavaTry>java LoadDriver
    Exception in thread "main" java.lang.NoClassDefFoundError: LoadDriver
    Below are the JAVA scripts which I used
    -> HelloWorld.java
    public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World!");
    -> LoadDriver.java
    import java.sql.*;
    public class LoadDriver {
    public static void main(String[] Args) {
    try {
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    /* Class.forName("com.mysql.jdbc.Driver").newInstance(); <- either one try the same */
    } catch (Exception E) {
    System.err.println("Unable to load driver.");
    E.printStackTrace();
    Moreover, I saw some information only standalone application need to set CLASSPATH, right??

    My problem "unable to load driver" have solved.
    I set the CLASSPATH = C:\mysql-connector-java-3.0.11-stable\mysql-connector-java-3.0.11-stable-bin.jar
    and try
    java -cp ".";%CLASSPATH% LoadDriver
    Thanks masnare again :> and who provided the link http://www.kevinboone.com/classpath.html in the forums others similar topics, actually I forgot which topic and who, so... :P no matter whom thanks very much :)

  • How can I optimize my hard disk drive usage and performance in Windows 8 or Windows 7?

    QuestionHow can I optimize my hard disk drive usage and performance in Windows 8 or Windows 7?
    AnswerThere are a few simple steps you can take to ensure your hard disk drive is used optimally.
    Use Toshiba HDD Protection
    Many Toshiba laptops come with a program called Toshiba HDD Protection pre-installed. This program helps to protect your hard disk drive from being damaged due to falls or impacts. By default, it should already be enabled. You might be tempted to lower the detection levels in this application, but doing so could cause your hard disk drive to be damaged. Remember that while the application can reduce the chance of damage, you should still avoid allowing the laptop to fall or suffer rapid impacts.
    For more information on this utility, see the following article:
    TOSHIBA HDD Protection
    Optimize the drive
    Windows 8 and Windows 7 optimize hard disk drives automatically through a process called defragmentation. Unless you've disabled this, you don't need to do anything. If you have disabled this and want to run the process, you can still do so.
    In Windows 8, search for "Defrag" at the Windows Start screen and select "Defragment and optimize your drives."
    In Windows 7, search for "Defrag" in the Start Menu's search field and select "Disk defragmenter."
    You can use this tool to optimize your hard disk drives, allowing Windows to find needed files faster.
    Remove items from startup
    Some applications run automatically when Windows starts. This can add additional functionality, but it also decreases the performance of your computer. Sometimes you might want to disable certain programs from starting automatically.
    In Windows 8, search for "Task Manager" at the Start screen. Select the "Startup" tab. Select an application you'd like to disable from starting automatically and then click the "Disable" button in the lower-right.
    In Windows 7, type "msconfig" in the Start Menu's search field and press ENTER. Uncheck the boxes next to applications you'd like to disable from starting automatically.
    You should be sure of the purpose of an application before disabling it from starting automatically. Some applications might be important. If in doubt, you might consider searching on the Web to discover more information about a program. Remember that if you find that you disabled something vital, you can always re-enable it.
    For more information, please see the following video:

    QuestionHow can I optimize my hard disk drive usage and performance in Windows 8 or Windows 7?
    AnswerThere are a few simple steps you can take to ensure your hard disk drive is used optimally.
    Use Toshiba HDD Protection
    Many Toshiba laptops come with a program called Toshiba HDD Protection pre-installed. This program helps to protect your hard disk drive from being damaged due to falls or impacts. By default, it should already be enabled. You might be tempted to lower the detection levels in this application, but doing so could cause your hard disk drive to be damaged. Remember that while the application can reduce the chance of damage, you should still avoid allowing the laptop to fall or suffer rapid impacts.
    For more information on this utility, see the following article:
    TOSHIBA HDD Protection
    Optimize the drive
    Windows 8 and Windows 7 optimize hard disk drives automatically through a process called defragmentation. Unless you've disabled this, you don't need to do anything. If you have disabled this and want to run the process, you can still do so.
    In Windows 8, search for "Defrag" at the Windows Start screen and select "Defragment and optimize your drives."
    In Windows 7, search for "Defrag" in the Start Menu's search field and select "Disk defragmenter."
    You can use this tool to optimize your hard disk drives, allowing Windows to find needed files faster.
    Remove items from startup
    Some applications run automatically when Windows starts. This can add additional functionality, but it also decreases the performance of your computer. Sometimes you might want to disable certain programs from starting automatically.
    In Windows 8, search for "Task Manager" at the Start screen. Select the "Startup" tab. Select an application you'd like to disable from starting automatically and then click the "Disable" button in the lower-right.
    In Windows 7, type "msconfig" in the Start Menu's search field and press ENTER. Uncheck the boxes next to applications you'd like to disable from starting automatically.
    You should be sure of the purpose of an application before disabling it from starting automatically. Some applications might be important. If in doubt, you might consider searching on the Web to discover more information about a program. Remember that if you find that you disabled something vital, you can always re-enable it.
    For more information, please see the following video:

  • External Hard Drive won't load, Disk Utility and System Profiler crashes,

    I've had the WD 1TB Passport for Mac for about a year now and as of this afternoon, my MacBook Pro stopped recognizing it. It's encrypted so when I plugged it in, my computer asked me for my password, but then it said there was an error and wouldn't mount. After restarting the computer, the password prompt for my external drive didn't even pop up. I can hear the hard drive spinning and the light flashes for a good 30 seconds before going solid. I have tested my USB ports with flash drives and they are reading them just fine. I tried to run  Disk Utility but it goes into the never-ending loading mode. So then I go to the "About my Mac" page and clicked on storage, and the profiler crashed (never-ending loading). Can anyone help me? It was working just fine up until today. I even tried different Micro USB chords on it. This drive is incredibly important to me and I would appreciate not having to erase anything from it (kinda defeats the purpose of backing up a computer if the external hard drive is the one needing the backup).
    I have a
    Mid 2010 13in MacBook Pro
    OS X 10.8.2
    1TB WD Passport for Mac

    Solution may be found if you search in the "More Like This" section over in the right column. 

  • Optimization on Load Time (Large Images and Sounds)

    Hi,
    I have an all flash website that works by having each portion of it to load and unload in the center of a frame based off the navigation chosen.  Load times on everything but one part of my site are ok.
    The dimensions of the part inside the frame are 968x674.  I know that's relatively large for a flash file, but that can't be changed at this point.
    Within the page there are objects that come up when you find an item on the screen.  Its a dialog box and it shows text, an image, and has a voice over that reads what the text says.  After you're done looking at it, there is an x-button to dismiss the window.  There are 15 of these and they are exported to the actionscript.  I add them in the actionscript via addChild.  I figured this is a huge spot that could be reconfigured, but I'm not sure if it would make much a difference.
    The other huge thing is there is a ton on the screen.  It starts you off in an environment, and when you click 3 different sections, it zooms into that portion allowing you to look for the items you're trying to find.
    There is also a man that talks and animates in the beginning and at the end.  We are planning on taking out the end part and putting a text box up.
    Here is the website..  its a propane safety site for kids.  I know its kind of a weird idea, but it works and people seem to like it.
    www.propanekids.com
    The two parts of the site we are trying to optimize is the main menu when you first are at the site, and the "Explore" section.  (Just click on the cloud on the front page.
    If someone could take the time to give me some new ideas of how I can get these loading times down, I would greatly appreciate it!
    Thanks

    Ok, who ever posted this message is hacking me  and i can't believe you guys are helping
    Date: Thu, 27 Jan 2011 11:07:28 -0700
    From: [email protected]
    To: [email protected]
    Subject: Optimization on Load Time (Large Images and Sounds)
    Hi,
    I have an all flash website that works by having each portion of it to load and unload in the center of a frame based off the navigation chosen.  Load times on everything but one part of my site are ok.
    The dimensions of the part inside the frame are 968x674.  I know that's relatively large for a flash file, but that can't be changed at this point.
    Within the page there are objects that come up when you find an item on the screen.  Its a dialog box and it shows text, an image, and has a voice over that reads what the text says.  After you're done looking at it, there is an x-button to dismiss the window.  There are 15 of these and they are exported to the actionscript.  I add them in the actionscript via addChild.  I figured this is a huge spot that could be reconfigured, but I'm not sure if it would make much a difference.
    The other huge thing is there is a ton on the screen.  It starts you off in an environment, and when you click 3 different sections, it zooms into that portion allowing you to look for the items you're trying to find.
    There is also a man that talks and animates in the beginning and at the end.  We are planning on taking out the end part and putting a text box up.
    Here is the website..  its a propane safety site for kids.  I know its kind of a weird idea, but it works and people seem to like it.
    http://www.propanekids.com
    The two parts of the site we are trying to optimize is the main menu when you first are at the site, and the "Explore" section.  (Just click on the cloud on the front page.
    If someone could take the time to give me some new ideas of how I can get these loading times down, I would greatly appreciate it!
    Thanks
    >

  • Itunes won't load CDs automatically and I have to restart it everytime to load 1 CD. I have ensured I have latest Itunes, latest DVD driver, start itunes from program library in safe mode but nothing works. Any ideas ?

    Itunes won't load CDs automatically and I have to restart it everytime to load 1 CD. I have ensured I have latest Itunes, latest DVD driver, start itunes from program library in safe mode but nothing works. Any ideas ?

    I have had a similar problem with my system. I just recently (within a week of this post) built a brand new desktop. I installed Windows 7 64-bit Home and had a clean install, no problems. Using IE downloaded an anti-virus program, and then, because it was the latest version, downloaded and installed Firefox 4.0. As I began to search the internet for other programs to install after about maybe 10-15 minutes my computer crashes. Blank screen (yet monitor was still receiving a signal from computer) and completely frozen (couldn't even change the caps and num lock on keyboard). I thought I perhaps forgot to reboot after an update so I did a manual reboot and it started up fine.
    When ever I got on the internet (still using firefox) it would crash after anywhere between 5-15 minutes. Since I've had good experience with FF in the past I thought it must be either the drivers or a hardware problem. So in-between crashes I updated all the drivers. Still had the same problem. Took the computer to a friend who knows more about computers than I do, made sure all the drivers were updated, same problem. We thought that it might be a hardware problem (bad video card, chipset, overheating issues, etc.), but after my friend played around with my computer for a day he found that when he didn't start FF at all it worked fine, even after watching a movie, or going through a playlist on Youtube.
    At the time of this posting I'm going to try to uninstall FF 4.0 and download and install FF 3.6.16 which is currently on my laptop and works like a dream. Hopefully that will do the trick, because I love using FF and would hate to have to switch to another browser. Hopefully Mozilla will work out the kinks with FF 4 so I can continue to use it.
    I apologize for the lengthy post. Any feedback would be appreciated, but is not necessary. I will try and post back after I try FF 3.16.6.

  • Driver dimension and data load dim

    Hello ,
    Can anyone explain the difference between Driver dimension and normal dimension..(data load dimension)
    Thank You!!!

    Hi,
    Driver dimensions are the varying column dimensions that reside in the data table or file (i.e. columns such as customer, product, date etc.). Single default members from other dimensions are fixed in the POV during data load (i.e. Actual scenario is usually fixed when loading actual data).
    Cheers,
    Alp

  • I loaded Mountain Lion and now my Canon Canoscan LIDE100 Scanner won't work. I reloaded the application, checked the driver & loaded the Canon driver for Mountain Lion. Aplication starts to load then hangs up on 80% complete.   Any suggestions?

    I loaded Mountain Lion and now my Canon Canoscan LIDE100 Scanner won't work. I reloaded the application, checked the Cannon website for the correct driver & loaded the Canon driver for Mountain Lion. Aplication starts to load then hangs up on 80% complete.   Any suggestions? 

    Might have a hardware issue that was caused by the minor liquid spill.
    Take it to Apple to have them look at it.  I think they do a free diagnostics.  That way you can find out what's wrong with your MB.
    Good luck....Hope you get it sorted out.

  • My computer hard drive crashed and all my i-tunes were lost - can I re-load them from my iPod?

    My hard drive crashed and destroyed all the i-tunes that I had burned from my CDs and purchased. The are still on my iPod Classic, can I load them on the computer, I have re-installed the i-tune program and the last purchase I made was re-installed, but nothing else.  I don't want to sync my iPod, iPhone and Shuffle and lose them.  What should I do?

    Your iPod is designed to sync with only one iTunes library at a time.  It will recognize the iTunes library on the reloaded PC as a new library.  If you sync the iPod with this new library, all content will be erased from the iPod and replaced with what is in the new library.  So what you will want to do is copy everything from the iPod to your new iTunes library on your PC first.
    See this older post from another forum member Zevoneer covering the different methods and software available to assist you with the task of copying content from your iPod back to your PC and into iTunes.
    https://discussions.apple.com/thread/2452022?start=0&tstart=0
    B-rock

  • I own a copy of Aperture. my hard drive crashed and i want to load aperture onto my new imac. how do i do it?

    I own a copy of Aperture. my hard drive crashed and I want to reoad aperture onto my new imac. how do i do it?

    Depends on how you bought Aperture to begin with..
    If you bought it from the Mac App Store simply log in to the MAS using the same Apple ID you used to buy it and download it
    If you bought Aperture on DVD you will need to install from the DVD using the serial number you received with the DVD package.
    If you bought Aperture through a digital download prior to the MAS, say a trial version you upgraded, things get a bit more complicated. You will need to install from the original DMG package file you downloaded and use the serial number Apple set you went you purchased it.

  • Unable to load Driver Class

    Hi There:
    When I try to connect to the Oracle 8i via this applet , I get the following run time error.
    Any help will be appreciated.
    I am using j2sdkee1.3.1, jdk1.3.1_02 and Oracle8.
    I also need your suggestion please. I have inserted some BLOB data in the Oracle table. I will need to display the BLOB data to the end users. I plan to convert this BLOB data into string format so that my applet can display the same. Further the string will have to be edited by the end users. I will then convert this modified string back to byte array so that I can insert the same as BLOB.
    Please let me know applet or the servlet? Which is better option.
    Users are reluctant to use any kind of WebServer because it will introduce the additional layer of complexity.
    Any help will be greatly appreciated.
    Thanks in advance.
    C:\>AppletViewer JdbcApplet.html
    Unable to load Driver Class
    java.lang.ClassNotFoundException: java.io.FileNotFoundException: C:\oracle\jdbc\
    driver\OracleDriver.class (The system cannot find the path specified)
    The following code snippet fails because it is unable to find the suitable driver.
    if (conn == null)
         //make a connection to the db
         try {     
              // conn = DriverManager.getConnection ("jdbc:oracle:thin:@"+"localhost:1521:sys", "system", "manager");
              // conn = DriverManager.getConnection ("jdbc:oracle:thin:system/manager@(description=(address_list= (address=(pro tocol=tcp)(host=localhost)(port=1521)))(source_route=yes)(connect_data=(sid=sys)))" );
              Class.forName("oracle.jdbc.driver.OracleDriver");
              String conurl="jdbc:oracle:thin:@localhost:1521:sys";
              Connection con=DriverManager.getConnection(conurl,"system","manager");
         } catch ( Exception e ) {
              System.out.println ("Unable to load Driver Class");
              e.printStackTrace (System.out);
              // add send email notification about this fact
              return false;
    } // End of if Statement from conn...

    Hi,
    maybe I'm too late but try the following :
    It seems that Your IDE doesn't check the path to Your classesxxx.zip file.
    Or Your classesxxx.zip file is corrupt.
    We had this error after downloading the classes12.zip for Oracle versions
    higher 8.1.6.
    The original size of this file is 1.888kB.
    Remember Windows FTP is downloading in ascii mode per default.
    Or Your classpath isn't correct
    ( the Exception souns like this )
    Regards

  • JDBC error - Unable to find or load Driver

    Hi,
    I'm attempting to connect to a MySQL database with using the statement below, using MySQL Connector 3.0.8:
    public void connectToDB() {
    try {
    connection = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/accounts?user=root&password=spider");
    } catch(SQLException connectException) {
    System.out.println(connectException.getMessage());
    System.out.println(connectException.getSQLState());
    System.out.println(connectException.getErrorCode());
    However, I obtain the error shown below when executing my code:
    C:\> java Accounts
    Unable to find and load Driver
    which is an output from:
    public Accounts() {
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (Exception e) {
    System.err.println("Unable to find and load driver");
    System.exit(1);
    My database is not located on another machine, but on the same machine rather (127.0.0.1) i.e. on my local PC.
    I've tried trouble shooting the problem by:
    C:\> telnet localhost 3306
    Bad Connection 4.0.20a-max@!5
    Connection to host lost
    C:\> ping 127.0.0.1
    4.0.20a-maCGxG;2&f,&#9787;
    Connection to host lost.
    C:\>ping 127.0.0.1:3306
    Ping request could not find host 127.0.0.1:3306. Please check the name and try a
    gain.
    C:\>ping 127.0.0.1
    Pinging 127.0.0.1 with 32 bytes of data:
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
    C:\>
    Could anyone kindly tell me where did I go wrong, and how do I go about solving this issue?
    Below is the complete set of code(Accounts.java) which querries, inserts and deletes entries in the database.
    Thanks in advance.
    // Accounts.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.util.*;
    public class Accounts extends JFrame {
    private JButton getAccountButton,
    insertAccountButton,
    deleteAccountButton,
    updateAccountButton;
    private JList accountNumberList;
    private Connection connection;
    private JTextField accountIDText,
    usernameText,
    passwordText,
    tsText,
    activeTSText;
    private JTextArea errorText;
    public Accounts() {
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch (Exception e) {
    System.err.println("Unable to find and load driver");
    System.exit(1);
    private void loadAccounts() {
    Vector v = new Vector();
    try {
    Statement statement = connection.createStatement();
    ResultSet rs = statement.executeQuery("SELECT acc_id FROM acc_acc");
    while(rs.next()) {
    v.addElement(rs.getString("acc_id"));
    rs.close();
    } catch(SQLException e) {
    displaySQLErrors(e);
    accountNumberList.setListData(v);
    private void buildGUI() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    accountNumberList = new JList();
    loadAccounts();
    accountNumberList.setVisibleRowCount(2);
    JScrollPane accountNumberListScrollPane = new JScrollPane(accountNumberList);
    //Do Get Account Button
    getAccountButton = new JButton("Get Account");
    getAccountButton.addActionListener (
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    Statement statement = connection.createStatement();
    ResultSet rs = statement.executeQuery("SELECT * FROM acc_acc WHERE acc_id = " + accountNumberList.getSelectedValue());
    if (rs.next()) {
    accountIDText.setText(rs.getString("acc_id"));
    usernameText.setText(rs.getString("username"));
    passwordText.setText(rs.getString("password"));
    tsText.setText(rs.getString("ts"));
    activeTSText.setText(rs.getString("act_ts"));
    } catch(SQLException selectException) {
    displaySQLErrors(selectException);
    //Do Insert Account Button
    insertAccountButton = new JButton("Insert Account");
    insertAccountButton.addActionListener (
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    Statement statement = connection.createStatement();
    int i = statement.executeUpdate("INSERT INTO acc_acc VALUES(" +
    accountIDText.getText() + ", " +
    "'" + usernameText.getText() + "', " +
    "'" + passwordText.getText() + "', " +
    "0" + ", " +
    "now())");
    errorText.append("Inserted " + i + " rows successfully");
    accountNumberList.removeAll();
    loadAccounts();
    } catch(SQLException insertException) {
    displaySQLErrors(insertException);
    //Do Delete Account Button
    deleteAccountButton = new JButton("Delete Account");
    deleteAccountButton.addActionListener (
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    Statement statement = connection.createStatement();
    int i = statement.executeUpdate("DELETE FROM acc_acc WHERE acc_id = " +
    accountNumberList.getSelectedValue());
    errorText.append("Deleted " + i + " rows successfully");
    accountNumberList.removeAll();
    loadAccounts();
    } catch(SQLException insertException) {
    displaySQLErrors(insertException);
    //Do Update Account Button
    updateAccountButton = new JButton("Update Account");
    updateAccountButton.addActionListener (
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    try {
    Statement statement = connection.createStatement();
    int i = statement.executeUpdate("UPDATE acc_acc " +
    "SET username='" + usernameText.getText() + "', " +
    "password='" + passwordText.getText() + "', " +
    "act_ts = now() " +
    "WHERE acc_id = " + accountNumberList.getSelectedValue());
    errorText.append("Updated " + i + " rows successfully");
    accountNumberList.removeAll();
    loadAccounts();
    } catch(SQLException insertException) {
    displaySQLErrors(insertException);
    JPanel first = new JPanel(new GridLayout(5,1));
    first.add(accountNumberListScrollPane);
    first.add(getAccountButton);
    first.add(insertAccountButton);
    first.add(deleteAccountButton);
    first.add(updateAccountButton);
    accountIDText = new JTextField(15);
    usernameText = new JTextField(15);
    passwordText = new JTextField(15);
    tsText = new JTextField(15);
    activeTSText = new JTextField(15);
    errorText = new JTextArea(5, 15);
    errorText.setEditable(false);
    JPanel second = new JPanel();
    second.setLayout(new GridLayout(6,1));
    second.add(accountIDText);
    second.add(usernameText);
    second.add(passwordText);
    second.add(tsText);
    second.add(activeTSText);
    JPanel third = new JPanel();
    third.add(new JScrollPane(errorText));
    c.add(first);
    c.add(second);
    c.add(third);
    setSize(500,500);
    show();
    public void connectToDB() {
    try {
    connection = DriverManager.getConnection(
    "jdbc:mysql://localhost:3306/accounts?user=root&password=spider");
    } catch(SQLException connectException) {
    System.out.println(connectException.getMessage());
    System.out.println(connectException.getSQLState());
    System.out.println(connectException.getErrorCode());
    private void displaySQLErrors(SQLException e) {
    errorText.append("SQLException: " + e.getMessage() + "\n");
    errorText.append("SQLState: " + e.getSQLState() + "\n");
    errorText.append("VendorError: " + e.getErrorCode() + "\n");
    private void init() {
    connectToDB();
    public static void main(String[] args) {
    Accounts accounts = new Accounts();
    accounts.addWindowListener(
    new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    accounts.init();
    accounts.buildGUI();
    }

    Hi,
    Below is my PATH setting to the MySQL JDBC JAR added in the autoexec.bat file:
    PATH C:\j2sdk1.4.1_01\bin;C:\mysql-connector-java-3.0.8-stable-bin.jar;%CLASSPATH%
    Could you tell me where did I go wrong & how can I fix this problem?
    FYI, I'm using a Windows XP platform.
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    C:\mysql\bin>net stop mysql
    The MySQL service is stopping..
    The MySQL service was stopped successfully.
    C:\mysql\bin>mysqld.exe
    C:\mysql\bin>net stop mysql
    The MySQL service is not started.
    More help is available by typing NET HELPMSG 3521.
    C:\mysql\bin>net start mysql
    The MySQL service is starting.
    The MySQL service was started successfully.
    I then tried initiating the MySQL client also on the same PC machine, but obtained the error below:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    C:\mysql\bin>mysql.exe
    ERROR 2003: Can't connect to MySQL server on 'localhost' (10061)
    C:\mysql\bin>telnet localhost 3306
    Connecting To localhost...Could not open connection to the host, on port 3306: C
    onnect failed
    C:\mysql\bin>
    Could you or anyone else help me on this problem? I'm still a newbie with MySQL and JDBC.
    Thanks in advance

  • Log4j:ERROR Failed to load driver

    I want to use log4j to log information,my jdk version is 1.5.0_06,and my oracle version is 9.2.0.1.0,my web.xml and servlet is follows:
    web.xml
    <servlet>          
    <display-name>LogServlet</display-name>
    <servlet-name>LogServlet</servlet-name>
    <servlet-class>
    test.a
    </servlet-class>
    <init-param>
    <param-name>log4j-config-file</param-name>
    <param-value>
    /WEB-INF/log4j.properties
    </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    /*a.java*/
    package test;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.apache.log4j.*;
    public class a extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ }
    public void init() throws ServletException{
    String prefix = getServletContext().getRealPath("/");
    String file = getServletConfig().getInitParameter("log4j-config-file");
    if (file != null) {
    PropertyConfigurator.configure(prefix + file);
    /*log4j.properties*/
    log4j.rootLogger=DEBUG,DATABASE
    log4j.addivity.org.apache=true
    log4j.appender.DATABASE.Threshold=INFO
    log4j.appender.DATABASE=org.apache.log4j.jdbc.JDBCAppender
    log4j.appender.DATABASE.URL=jdbc:oracle:thin:@192.1.1.2:1521:Ora
    log4j.appender.DATABASE.driver=oracle.jdbc.driver.OracleDriver
    log4j.appender.DATABASE.user=scott
    log4j.appender.DATABASE.password=tiger
    log4j.appender.DATABASE.sql=INSERT INTO test VALUES('%m')
    log4j.appender.DATABASE.layout=org.apache.log4j.PatternLayout
    When I start Tomcat,it raise following error:
    log4j:ERROR Failed to load driver
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1352)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:164)
    at org.apache.log4j.jdbc.JDBCAppender.setDriver(JDBCAppender.java:351)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.log4j.config.PropertySetter.setProperty(PropertySetter.java:205)
    at org.apache.log4j.config.PropertySetter.setProperty(PropertySetter.java:164)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:129)
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:96)
    at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:654)
    at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
    at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:509)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:415)
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:316)
    at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:324)
    at test.a.init(a.java:20)
    at javax.servlet.GenericServlet.init(GenericServlet.java:211)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3915)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4176)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:910)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:873)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
    at org.apache.catalina.core.StandardService.start(StandardService.java:450)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    I have put all jar file of the directory C:\oracle\ora92\jdbc\lib,such as classes12.jar,classes12_g.jar,classes12dms.jar,classes12dms_g.jar,nls_charset11.jar,nls_charset12.jar,ocrs12.jar,ojdbc14.jar,ojdbc14_g.jar into the direcory tomcat5\webapps\ROOT\WEB-INF\lib
    But Tomcat still raise above error? Why? I am puzzled with it for a long time! Anybody meet with above question? Any idea will be appreciated!

    Well, classes12.zip is a fairly old driver, especially for JDK 1.5, and even for Oracle 9. So, I would first suggest visiting Oracle's JDBC driver download sie.
    If that fails, please post the code you are using to connect to your database (please do not post the real domain or your user name or password). :^)
    - Saish

  • Error loading driver: java.lang.ClassNotFoundException: oracle.jdbc.driver.

    Hi!!!
    I�m trying to execute a example program included in http://archive.coreservlets.com/, the file is FruitTest.java....this compile very well...but....when i tried to execute it i have the following error:
    Error loading driver: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    Could somebody tell me what i have to add to my classpath?...and how to know if i have to download something and in what link is it?......
    Thanks in advance...
    Mary

    Hi mary,
    Please try following code, but before that please include classes12.zip in ur classpath. This file contains the oracle thin driver.
    Connection connection = null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String url = "jdbc:oracle:thin:@dbUrl"
    connection = DriverManager.getConnection(url, "dbName", "password");
    }catch (Exception e){
    e.printStackTrace();
    good luck ...san :-)

Maybe you are looking for