?
Solved

Where to Locate SQL URL

Posted on 2004-11-29
8
Medium Priority
?
309 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:jackjoker
  • 4
  • 2
  • 2
8 Comments
 
LVL 13

Assisted Solution

by:petmagdy
petmagdy earned 500 total points
ID: 12702971
make sure ur MySQL driver is in ur classpath
0
 

Author Comment

by:jackjoker
ID: 12702977
Can you elaborate on that? Where's my classpath?
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12702979
also i think the code should be:

String jdbcDriver = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/staffdb";
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Expert Comment

by:petmagdy
ID: 12702984
do u run ur code in an IDE or with JDK command line? if IDE which?
0
 

Author Comment

by:jackjoker
ID: 12703011
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12703023
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
 
LVL 15

Accepted Solution

by:
Javatm earned 500 total points
ID: 12703075
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
 
LVL 15

Expert Comment

by:Javatm
ID: 12703096
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question