Where to Locate SQL URL

How can I find out the SQL DB driver url for my machine?

I'm having problems with this set of codes. ClassNotFoundException.

String jdbcDriver = "com.mysql.odbc.Driver";
String dbURL = "odbc:mysql://localhost:3306/staffdb";
Class.forName(jdbcDriver);
con=DriverManager.getConnection(dbURL);

Thanks
jackjokerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
make sure ur MySQL driver is in ur classpath
0
jackjokerAuthor Commented:
Can you elaborate on that? Where's my classpath?
0
petmagdyCommented:
also i think the code should be:

String jdbcDriver = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/staffdb";
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

petmagdyCommented:
do u run ur code in an IDE or with JDK command line? if IDE which?
0
jackjokerAuthor Commented:
I ran in with JCreator, and also on a JSP (running Tomcat). I've tried jdbc but it doesn't work too.

The error message is: "Problem with loading db driver.........com.mysql.jdbc.Driver"
0
petmagdyCommented:
first ur code must look like (but not exactly) this:

     Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/staffdb",
        "root", "secret");

second go to:

http://dev.mysql.com/downloads/connector/j/3.0.html

dowload a file called mysql-connector-java-3.0.16-ga.zip

third:

 unzip this file for example to directory c:\MyDir, u will find a jar file at c:\MyDir\mysql-connector-java-3.0.16-ga\mysql-connector-java-3.0.16-ga-bin.jar

fouth:

add this jar to ur JCreator Java Project Libraries (which represents ur class path)

0
JavatmCommented:
You got to use the MySQL driver for java :

MySQL Connector/J
http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.0.16-ga.zip/from/pick

Then unzip it and add mysql-connector-java-3.0.16-ga-bin.jar to your classpath. Or you can just
simply paste mysql-connector-java-3.0.16-ga-bin.jar to the JAVA_HOME/jre/lib/ext folder.

Then re-compile the whole program again. You find all the info you need at MySQL site.

Hope that helps . . .
Javatm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JavatmCommented:
If you encounter errors in your codes you can refer to this :

       try {  
            // MySQL Server Direct Connection
            Class.forName("com.mysql.jdbc.Driver").newInstance();

            // You have to specify the locahost/port/database/username/password
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users?user=Sample&password=0101");
            stmt = con.createStatement();  
           
            query = "SELECT * FROM Records";
           
            rs = stmt.executeQuery(query);

            // Do your thing here . . .

            stmt.close();
        }
        catch(Exception e) {
            System.out.println("Error in Insert User.");
        }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.