The code at the bottom of this message is an example (1 of 3 i have tried) of trying to connect to a localhost mysql database.
It wont, and the exception displayed is the one i have set.
Im fairly convinced its something to do with the driver not being installed.
I have downloaded it and unzipped it and installed it, and got the green success tick.
But it still will not connect.
How do i set a class path?
My only other option is to dual boot windows, which i really dont want to do.
Expand|Select|Wrap|Line Numbers
- import java.sql.*;
- public class Connect
- {
- public static void main (String[] args)
- {
- Connection conn = null;
- try
- {
- String userName = "root";
- String password = "root";
- String url = "jdbc:mysql://localhost:3306/test/";
- Class.forName ("com.mysql.jdbc.Driver").newInstance ();
- conn = DriverManager.getConnection (url, userName, password);
- System.out.println ("Database connection established");
- }
- catch (Exception e)
- {
- System.err.println ("Cannot connect to database server");
- }
- finally
- {
- if (conn != null)
- {
- try
- {
- conn.close ();
- System.out.println ("Database connection terminated");
- }
- catch (Exception e) { /* ignore close errors */ }
- }
- }
- }
- }