mysql-connector-java-5.0.4-bin-g.jar not connecting
- From: "Jevan" <jp@xxxxxxxxxx>
- Date: Tue, 26 Dec 2006 16:51:20 +1100
I have mysql-connector-java-5.0.4-bin-g.jar in my classpath. Whenever I run
the java program I get "Cannot instantiate jdbc driver". Class.forName
("com.mysql.jdbc.Driver").newInstance(); keeps throwing an exception.... Any
suggestions?
Mysql is definitely working because I can access it from Apache Webserver
using PHP5, and also I can access it from the command line login (mysql).
Java is also working because it does run, just it throws an exception when
it gets to "forName". I'm thinking perhaps it doesn't like version 5.0.4 of
the connector? I'm planning to download JConnector 3.1.14 which will
hopefully then work.. but I thought I'd mention this...
JP
compile.bat
G:\Program Files\Java\jdk1.5.0_10\bin\javac" -classpath
G:\data\java\classes\mysql-connector-java-5.0.4-bin-g.jar MySqlOne.java
pause
run.bat
"G:\Program Files\Java\jdk1.5.0_10\bin\java" -classpath
sG:\Data\Java\classes\mysql-connector-java-5.0.4-bin-g.jar;g:\data\java\clas
ses\ MySqlOne
pause
MySqlOne.java
//package example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
import java.io.*;
import java.awt.*;
//import javax.servlet.http.*;
//import javax.servlet.*;
public class MySqlOne {
public static void main(String[] args) {
//try {
//Connection conn = DriverManager.getConnection("jdbc:mysql:
//localhost/test?user=root&password=");
//} catch (SQLException ex) {
//out.println("SQLException: " + ex.getMessage());
//out.println("SQLState: " + ex.getSQLState());
//out.println("VendorError: " + ex.getErrorCode());
//}
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost/test";
try {
Class.forName ("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
System.err.println ("Cannot instantiate jdbc driver");
// handle the error
}
try {
Connection conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
} catch (Exception ex) {
System.err.println ("Cannot connect to database server");
}
//try {
//Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=
");
// Do something with the Connection
//} catch (SQLException ex) {
// handle any errors
// System.out.println("SQLException: " + ex.getMessage());
// System.out.println("SQLState: " + ex.getSQLState());
// System.out.println("VendorError: " + ex.getErrorCode());
//}
System.out.println("Finished.");
}
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
.
- Prev by Date: Tools for building a db init script, perhaps besides Commons Jelly SQL
- Next by Date: newbie, problem with hibernate
- Previous by thread: Tools for building a db init script, perhaps besides Commons Jelly SQL
- Next by thread: newbie, problem with hibernate
- Index(es):
Relevant Pages
|
|