Problem while trying to connect to mySql server via JDBC...
Posted by:
vroxopoios
Date: December 14, 2004 05:49PM
I am using a very simple Java program for connecting to an also simple mySql database. I am using J2SE v.1.4.1, mySql v. 4.1 and the 3.1.5-gamma version of the mysql connector/J. I have of course installed the connector as specified in the documentation, by copying the 'mysql-connector-java-3.1.5-gamma-bin.jar' file in the $JAVA_HOME/jre/lib/ext directory, which is also declared in the CLASSPATH environment variable.
The code is very simple, something like this:
.....
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e)
{
System.out.println("Problem Description: " + e.getMessage());
}
String username = "root";
String password = "root";
String url = "jdbc:mysql://localhost/test";
try
{
Connection con = DriverManager.getConnection(url,username,password);
//Connection con = DriverManager.getConnection("jdbc:mysql:///test?user=root&password=root");
Statement stmt = null;
ResultSet rs = null;
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT ....");
......
} catch (SQLException se)
{
System.out.println(se.getSQLState());
System.out.println(se.getMessage());
}
Although everything is kept as simple as possible, and should be working according to the documentation, the following errors occur when running the code:
Problem Description: com.mysql.jdbc.Driver
-----> from the 1st try-catch block
08001
No suitable driver
-------> from the 2nd try-catch block
I have tried to create the Connection object using both ways as seen from the code fragment above, but with no luck eitherways...
Please note that I haven't written Java code for a long time, so there might be a chance that there is a coding error from my part, although I think that's not the case...
It is not my first time dealing with JDBC though; I have used Oracle DBMS and driver succesfully in the past. But is seems that we are not getting along well with mySql so far :(
Any ideas? Sorry for the long post.
Thank you in advance for your assistance.
Subject
Written By
Posted
Problem while trying to connect to mySql server via JDBC...
December 14, 2004 05:49PM
December 15, 2004 07:34AM
December 15, 2004 07:49AM
December 15, 2004 11:20AM
December 16, 2004 03:24AM
December 18, 2004 02:06PM
December 19, 2004 08:42AM
December 29, 2004 02:55PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.