Ecco la classe con la quale cerco di connettermi al db:
codice:
// LoadDriver.java
import java.sql.*;
public class LoadDriver {
public static void main(String args[]) {
// Load the driver to allow connection to the db
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception e) {
System.err.println("Failed to load JDBC/MySQL driver");
e.printStackTrace();
System.exit(1); // terminate the program
}
try {
System.out.println("I'm going to connect to database");
Connection c =
DriverManager.getConnection("jdbc:mysql://localhost/test?user="
+ "nobody&password=nobody");
System.out.println("I have connected to database");
}catch (SQLException e) {
System.out.println("Exception: " +
e.getMessage());
System.out.println("SQLState: " +
e.getSQLState());
System.out.println("VendorError: " +
e.getErrorCode());
e.printStackTrace();
}
}
}