简体   繁体   中英

MySQL JDBC issues

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()); 
    } 

Try catching Throwable instead of 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM