Problemas de MySQL JDBC
Frecuentes
Visto 83 equipos
0
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://172.16.2.10:57983/db1320939_sa63898_main";
Connection conn = DriverManager.getConnection(url,"u1320939_kd","svpgalway21");
conn.close();
System.out.println("It worked!");
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
1 Respuestas
0
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 java mysql jdbc or haz tu propia pregunta.
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? - fvu
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. - Tejas Kalewhy do you conn.close(); it causes your connection to close - user3470953
Any exceptions/errrors? - Vimal Bera
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 - user3240957