Problemas de MySQL JDBC

I'm currently working on a small project which involves writing information from a CSV file to a MySQL database.

I'm using netbeans and have added the MySql JDBC JAR file to the project which is needed for the connection. When running the code below the program does not move on past the driver manager.getConnection statement. I am lost for ideas at this stage. My username and password is definitely correct and I am certain I have the URL right. No errors are returned, the project seems to just get stuck.

I am using a database that is hosted by blacknight hosting services, would this make a difference?

 public static void writeToDatabase()

 try { 
        String url = "jdbc:mysql://"; 
        Connection conn = DriverManager.getConnection(url,"u1320939_kd","svpgalway21"); 

        System.out.println("It worked!");
    } catch (Exception e) { 
        System.err.println("Got an exception! "); 

preguntado el 28 de mayo de 14 a las 12:05

The IP address in the URL is a private address, so the database server and the computer running this code need to be on the same private network. Is that the case? -

It is most likely stuck while trying to connect to the db, and waiting for getConnection() to return. It should terminate with an exception after a timeout. -

why do you conn.close(); it causes your connection to close -

Any exceptions/errrors? -

I let it run there for awhile and I got a communications link failure error. When going through the debugger the program sticks on the getConnection line. The database server and the computer running the code are not on the same network no -

1 Respuestas

Intenta atrapar Throwable en lugar de Exception. Maybe you're getting an Error while you connect to the DB and you wouldn't notice it. Also include a finally clause with a trace.

contestado el 28 de mayo de 14 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.