I'm using the following code to try to establish a connection with my database, I get "Cannot connect to database server" when I run it.
When I debug, I get this list of error but it doesn't effect the build
debug:
Have no file for /usr/lib/jvm/java-6-openjdk/jre/lib/netx.jar
Have no file for /usr/lib/jvm/java-6-openjdk/jre/lib/plugin.jar
Have no file for /usr/lib/jvm/java-6-openjdk/jre/lib/modules/jdk.boot.jar
Called the mysqlconn method!
Cannot connect to database server
BUILD SUCCESSFUL (total time: 0 seconds)
import java.sql.*; public class Main { public static void main(String[] args) { mysqlconn(); } public static void mysqlconn(){ System.out.println("Called the mysqlconn method!"); Connection conn = null; try { String userName = "root"; String password = "password"; 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 */ } } } } }