How to add JDBC Driver to my CLASSPATH

Hi~
I use MySQL JDBC Driver in my program like that
Class.forName("com.mysql.jdbc.Driver");But when I try to run it, I got a ClassNoFound Exception,I hava add mysql-connector-java-5.0.3-bin.jar into my CLASSPATH, but it no use.How to fix it ?
Thanks for your time~ ^_^

Here's my code, Thank you very much. But I suggest that,you'd better write your own code to test it. Hehe,thanks~~
import java.sql.*;
import java.util.*;
import java.io.*;
public class DBTest {
     private static Connection getConnection(String url, String username, String password)
          throws SQLException, IOException{
               try{
                    Class.forName("com.mysql.jdbc.Driver");
               }catch(ClassNotFoundException e){
                    e.printStackTrace();
          return DriverManager.getConnection(url, username, password);
     private static void runTest(){
          Scanner stdin = new Scanner(System.in);
          String serverUrl, username, password;
          serverUrl = "jdbc:mysql://localhost:3306/test";;
          username = stdin.nextLine();
          password = stdin.nextLine();
          Connection conn =null;
          try{
               conn = getConnection(serverUrl, username, password);
          }catch(SQLException e){
               e.printStackTrace();
          }catch(IOException e){
               e.printStackTrace();
          }finally{
          try{
               Statement stat;
               if(conn != null){
                     stat = conn.createStatement();
                     stat.executeUpdate("CREATE TABLE Greetings (Message VARCHAR(20))");
                     stat.executeUpdate("INSERT INTO Greetings VALUES('Hello mysql')");
                     ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
                     result.next();
                     System.out.println(result.getString(1));
               //      stat.executeUpdate("DROP TABLE Greetings");
          }catch(SQLException e){
               e.printStackTrace();
          }finally{
               try{
                    if(conn != null)
                         conn.close();
               }catch(SQLException e){
                    e.printStackTrace();
     public static void main(String args[]){
          runTest();          
}

Similar Messages

  • How to add JDBC driver?

    HI,
    I am using JDeveloper 9.0.5.2, the available jdbc driver database connection is thin and oci8, how can I add more driver availbe? Since oci8 using ocijdbc9, but I have installed Oracle client 10g which comes with the 10g driver.
    Thanks a lot.

    Select Tools>Project Properties and add the driver jar file in the Paths>Additional Classpaths field.
    thanks,
    Deepak

  • What file name is for the driver of gpib-usb-b?and how to add the driver file to vb in win2000??thanks

    what file name is for the driver of gpib-usb-b?and how to add the driver file to vb in win2000??thanks

    Hi,
    Multiple files are required for the proer fnctioning of any of our GPIB products. Unfortunatly the installation is not as simple as copying a single file over. If you wish to make the installer silent, i believe this is entirely possible in a fashion similar to the details given at http://digital.ni.com/public.nsf/websearch/0730A66245E6808086256CA8006E2183?OpenDocument.
    Hope this helps out!
    Best Regards,
    Aaron K.
    Application Engineer
    National Instruments

  • How to add tape drive in hyper V operating system

    how to add tape drive in hyper V operating system
    tape drive may be to scsci or USB port.
    how to add pls suggest

    how to add tape drive in hyper V operating system
    tape drive may be to scsci or USB port.
    how to add pls suggest
    You need something like StarWind Tape Redirector that "iSCSI-izes" hardware attached to host. So you'll be able to connect with iSCSI initiator from inside a VM running on this host, some other host or even other physical machine (as long as it
    has iSCSI connectivity), see:
    StarWind Tape Redirector
    http://www.starwindsoftware.com/download-starwind-tape-redirector
    So at the end of the day you'll have something like on the picture below:
    Good news: this software offering is 100% free so you don't need to pay anything to anybody :)
    Hope this helped!
    StarWind Virtual SAN clusters Hyper-V without SAS, Fibre Channel, SMB 3.0 or iSCSI, uses Ethernet to mirror internally mounted SATA disks between hosts.

  • Need Help On How to Install JDBC Driver

    I've downloaded the JDBC driver and set the CLASSPATH environmental variable to the .jar file that is the same one I downloaded that is in the oracle folder. (not sure why I have to download it again) But, there are no other instructions on installation. I also tried copying the jdbc folder I downloaded to replace the one within the oracle folder and that didn't work either. If I type "import oracle." etc in netbeans it does not recognize the class / package. I can't be sure what the installation process is.
    I can't find clear instructions on installing JDBC other than the readme which says all you have to do is set the CLASSPATH, but it doesn't even mention what to do with the files you download. I found a developers reference that says all the things to check to make sure it installed correctly, but that is after the fact and I don't know how to get there.
    Thank you

    I already have the CLASSPATH set in the system environmental variables for ojdbc6.jar and orai18n.jar and it does not work.
    '.;C:\Program Files\Java\jre1.6.0_06\lib\ext\QTJava.zip;C:\app\0\product\11.1.0\db_1\jdbc\lib\ojdbc6.jar;C:\app\0\product\11.1.0\db_1\jlib\orai18n.jar"
    Also, I'd rather not have to run a TCP/IP listener so the OCI based JDBC driver would be preferred. Do I need to the OCI and the OCI based JDBC? (I read there is a difference) If so, could somebody give me the URL's because I can't find them.
    I find this very confusing. I found the page for JDBC, but that takes me to the JDBC page with many downloads and then they are all thin versions. So at the bottom it has a small link for "platform specific JDBC-OCI libraries See the instant client" so I click on the "instant client" (whatever that is) but that just has a download link for a zip file that has a readme with nothing other than a timestamp and a useless header with no information. This is just taking me in circles.
    What I want to do is start programming java in netbeans using JDBC. Thanks.

  • How to add new driver to create master repository database

    Dear All,
    i want to creade ODI Repositroy Database on SQL SERVER,
    when i click the driver button in "Create Repository Wizard" the only driver i found for sql serve ris just able to connect to sql server 2000
    i got a driver written by microsoft to connect to sql server 2005, but how can i add this driver where i can see it in the driver list ???
    i have jar file. i put it in the drivers folder in the installation folder of the ODI but akso it doen't appear.
    may you please help me to be able to see this driver in the driver list of "CREATE Master Repository Wizard" ??????????????????????????
    Regards,
    Ahmed Salah

    Hi,
    Copy the sql server driver into the oracledi\drivers directory and restart the create repository
    You need to manually enter the driver name and url for sql server 2005
    e.g.
    com.microsoft.sqlserver.jdbc.SQLServerDriver
    jdbc:sqlserver://<sqls machine>:1433;databaseName=<db name>;integratedSecurity=false
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • How to use JDBC driver (type 4) with struts?????

    Hi! have a nice day!!!!!
    i want to connect database use struts with JDBC driver type 4. i must add <data-source/> to <data-sources></data-sources> tag but i don't know how to use <data-source/> with it's properties. please tell me! thank very much

    thank for reply!!! :D
    my project require to use struts 1.2.8 with ODBC (i think so it's type 1) for connect to database (SQL server). i think so it has two step :
    1. edit file struts-config.xml with <data-sources> tag.
    2. programming in file java (which extends from Action class) connect to database.
    but how to programming in file java??? (i think so must use objects DataSource & Connection)

  • How to load jdbc driver?

    I don't really understand the tutorial when it says to download a driver.
    (I use mySql)
    http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
    That really doesnt describe it well, since i really am new to JDBC.
    What do i need to do in order to make the "driver" work with mysql databases?
    What about other databases, such as oracle?

    What do i need to do in order to make the "driver" work with mysql databases?
    What about other databases, such as oracle? For any database you want to use, the driver needs to be accessible in your classpath/buildpath
    and what do i need to import?You need to import java.sql.*;
    In standard java code there are two important lines to get the connection
    String jdbcDriverClass = "com.myql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/myDatabase"
    String userName = "username";
    String password = "password"
    Class.forName(jdbcDriverClass);
    Connection con = DriverManager.getConnection(url, userName, password);The DriverClass name is different for every database
    The url connection is different for every database. For Oracle there are even two different connection strings you can use, depending upon whether you want to use their "thin" driver or the "oci" driver.
    Both the driver class name, and the URL connection string will be available from the documentation with the JDBC driver.
    Cheers,
    evnafets

  • HT1178 how to add usb drives to time capsule after initial setup

    How to add USB hard drives to TC after TC is already setup then access the usb drives by both PC and mac?

    1. Just plug them in. The drives need to be formatted as FAT16, FAT32, or Mac OS Extended (Journaled), and may need to be connected through a powered USB hub.
    2. Click here for information.
    (82647)

  • How to add hard drive manually (from CLI, not using VM Manager)

    How do you add hard drive manually from command-line, not from VM Manager?
    TIA.

    Please elaborate. A physical hard drive? Virtual? To the host? To a VM?

  • Loading JDBC driver dynamicly (without CLASSPATH)

    Problem:
    Need loading driver for database MySQL without
    using enviroment variable CLASSPATH.
    I try this using URLClassLoader
    URL []url = new URL[1];
    url[0] = new URL("file:\\d:\\Sergei\\Work\\MySlateDB\\MySqlDriver\\mm.mysql-2.0.6.jar");
    URLClassLoader loader = new URLClassLoader(url);
    DriverManager.registerDriver((Driver)Class.forName("org.gjt.mm.mysql.Driver",true,loader).newInstance());//.newInstance();
    Enumeration e=DriverManager.getDrivers();
    Driver loading, but DriverManager do not register it.
    Enumeration e is empty....
    Connection cn = DriverManager.getConnection("jdbc:mysql:\\172.16.9.200\\astra?user=SERGEY&password=QWE");
    And accordingly create exception "no Suitable driver"
    Why DriverManager do not register driver ?
    if add jar-archive in CLASSPATH then all working.
    How solve this problem ?
    Best regards, Rinver.

    You going to have to write your own version of DriverManager to do this. java.sql.DriverManager only uses the system classloader to load JDBC drivers.
    You can get an example from here:
    http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/squirrel-sql/squirrel-sql/fw/src/net/sourceforge/squirrel_sql/fw/sql/
    The files you are interested in are SQLDriverManager.java and SQLDriverClassLoader.java.
    Col

  • Installing a JDBC-driver in the classpath in win 2000

    Hi
    I'm trying to make an aplication, that can access a remote DataBase, with the mm.mysql driver.
    I have tryed to add the path to the libery where the jar file is in the classpath (in win 2000). But I can't get it to work from a dos-promt.

    put it in your enviroment.
    Control Panel -> System -> Enviroment.

  • How to register jdbc Driver in Applet

    Dear Sir,
    i am running a applet through jsp
    i am using following softwares
    jakarta-tomcat-4.1.10
    mysql 3.23.52-max
    jsp
    j2sdk1.3.1
    Linux 7.3
    Netscape 4.*
    the problem is when i am trying to load the applet in jsp
    <jsp:plugin type="applet" code="XX" width="XX" height="XX">
    </jsp:plugin>
    it gives following message
    the page contains information of type
    (application/x-java-applet;jpi-version=1.4) that can we viewer with
    appropriate Plug-in , so i am using applet tag
    but it is running fine in browser if i give .html extension
    the other problem is , my normal jsp are running and getting connected to Mysql
    but when i use applet it is giving error ClassNot Found Error, i have included jar
    file mysql-connector-java-3.0.1-beta in my class path
    do i have to install the jar file on the client m/c as applet runs on client m/c
    how to register driver in Applet
    thank you
    sunil

    I'm not sure about the jsp page thing but to get your mysql working in the applete what you need to do is in the <Applete> tag where you have archive=myclass.jar add this to it archive="myclass.jar, mysql-connector-java-3.0.1-beta.jar"
    make sure the mysql...jar is in the same dir as your jar file and the database server is on the same machine. It won't let you connect from an applete to a database that's on a diffrent machine. You'll get an access denied error.
    For the jsp page try putting your class as the code="my.class" and add archive="same stuff to fix <Applete>"
    that might work.
    Hope I gave you enough info to get you on the right track.
    Matt S.

  • How to register jdbc driver in java application

    Using Java Studio Enterprise:
    1. Add mssqlserver.jar to Libraries.
    2. jar contains package: com.microsoft.jdbc.sqlserver,
    package contains SQLServerDriver.class
    Trying to register this driver in program with:
    Class.forName("com.microsoft.jdbc.SQLServerDriver");
    raises exception ClassNotFoundException
    Maybe I should put mssqlserver.jar to specific folder?
    For web application using same driver works fine.

    hi,
    Class.forName("com.microsoft.jdbc.SQLServerDriver");
    raises exception ClassNotFoundExceptionFirst you check weather these jar files is in your lib <folder>
    msbase.jar,mssqlserver.jar,msutil.jar
    if no, copy that files and try it,

  • [SOLVED] How to add cd drive to wine? (mounted at cdda://sr0)

    Trying to allow wine access to my cd drive and having difficulties.
    My drive automounts at cdda://sr0 and can't figure out a way to get wine to access it. 
    How are you guys managing it?
    Last edited by ctarwater (2011-10-17 01:56:05)

    karol wrote:Run winecfg and go to the 'Drives' tab.
    cdda usually means an AudioCD, never tried that.
    It is an audio cd, I'm playing around with EAC (I know, I know, there are good native replacements).
    If I open the 'drives' tab in winecfg and try 'autodetect' it doesn't list my drive.  If I try to add it manually I have to navigate to it but cdda doesn't exist anywhere for me to navigate to.

Maybe you are looking for