Hi there,
This thread is very similar to an earlier thread but I didn't want to hijack a thread.
The issue is this. I have a mysql database on my local machine, I have installed the driver for Java and MySQL and using Eclipse I can connect to the database and see the tables etc.
What I want to do is have a class that defines how to connect to a database and so I have been working on developing one. The code I have so far is:
When I run this code the output in the console is:
There are apparently zero problems with the code in terms of compilation. Yet the Class.forName is throwing an exception.
This really is the only output - it's certainly the only output I can see. If someone could point me in the right direction I would really appreciate it.
Many thanks
nathj
This thread is very similar to an earlier thread but I didn't want to hijack a thread.
The issue is this. I have a mysql database on my local machine, I have installed the driver for Java and MySQL and using Eclipse I can connect to the database and see the tables etc.
What I want to do is have a class that defines how to connect to a database and so I have been working on developing one. The code I have so far is:
Code:
package database.scratch;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseConnector {
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///test",
"root", "passowrd");
if(!con.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}
Code:
Exception: com.mysql.jdbc.Driver
This really is the only output - it's certainly the only output I can see. If someone could point me in the right direction I would really appreciate it.
Many thanks
nathj
Comment