I am having problems trying to get a database connection using the following code:
try { Class.forName("com.mysql.jdbc.Driver"); Properties p = new Properties(); p.put("user", user_name); p.put("password", password); connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/jsp_test", p); } catch (SQLException ex) { // handle any errors ex.printStackTrace(); System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); return false; } catch (ClassNotFoundException e) { e.printStackTrace(); }
Error message displayed:
/ USR / Library / JVM / Java-6-OpenJDK / bin / Java -Didea.launcher.port = 7532 -Didea.launcher.bin.path = / usr / bin / idea / bin -Dfile.encoding = UTF-8 - classpath / usr / lib / jvm / java-6-openjdk / jre / lib / jce.jar: / usr / lib / jvm / java-6-openjdk / jre / lib / about. jar: /usr/lib/jvm/java-6-openjdk/jre/lib/resources.jar: /usr/lib/jvm/java-6-openjdk/jre/lib/management-agent.jar: / USR / Library /jvm/java-6-openjdk/jre/lib/jsse.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/charsets.jar:/usr/lib/jvm/java-6-openjdk /jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext /sunjce_provider.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/dnsns.jar : / home / going to bed / Java Projects / db_demo / out / production / db_demo: /opt/java/jre/lib/ext/mysql-connector-java-5.1.10-bin.jar: / usr / bin / idea /lib/idea_rt.jar com.intellij.rt.execution.application.AppMain Main com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communication link error
The last packet the server sent successfully was 0 milliseconds ago. The driver did not receive any packets from the server. in sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) with sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:57) in sun.reflect.DelegatingConstruor. javrutlava.java .newInstance (Constructor.java//32) in com.mysql.jdbc.Util.handleNewInstance (Util.java:406) in com.mysql.jdbc.SQLError.createCommunicationsException (SQLError.java:1074) in com.mysql.jdbc. ConnectionImpl.createNewIO (ConnectionImpl.java:2214) in com.mysql.jdbc.ConnectionImpl. (ConnectionImpl.java:781) in com.mysql.jdbc.JDBC4Connection. (JDBC4Connection.java:46) in sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) when sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:57) in sun.reflect.Delegatingorplpllectlectstructorlectstructorlectstructorlectstructorlectstructorlectstructorstructor java.lang.reflect.Constructor.newInstance (Constructor.javaβ32) in com.mysql.jdbc.Util.handleNewInstance (Util.java:406) in com.mysql.jdbc.ConnectionImpl.getInstance (ConnectionImpl.javahaps52) in com.mysql.jdbc.NonRegisteringDriver.connect (NonRegisteringDriver.java:284) in java.sql.DriverManager.getConnection (DriverManager.java:620) in java.sql.DriverManager.getConnection (DriverManager.java:169). Database.connect (Database.java:80) on Main.main (Main.java:13) in sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) with sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) in sun .reflect.DelegatingMethodAccessorImp l.invoke (DelegatingMethodAccessorImpl.java:43) in java.lang.reflect.Method.invoke (Method.java:616) in com.intellij.rt.execution.application.AppMain.main (AppMain.java:110) Called: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communication link error
The last packet the server sent successfully was 0 milliseconds ago. The driver did not receive any packets from the server. in sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) with sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:57) in sun.reflect.DelegatingConstruor. javrutlava.java .newInstance (Constructor.java//32) in com.mysql.jdbc.Util.handleNewInstance (Util.java:406) in com.mysql.jdbc.SQLError.createCommunicationsException (SQLError.java:1074) in com.mysql.jdbc. MysqlIO. (MysqlIO.javahaps43) in com.mysql.jdbc.ConnectionImpl.createNewIO (ConnectionImpl.java:2137) ... 18 more Caused: java.net.ConnectException: connection refused java.net.PlainSocketImpl.socketConnect (Native Method) when java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java data 10) in java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:176) in java.net.AbstractPlainSocketImpl.connect (AbstractPlain.net16lava.java. SocksSocketImpl.connect (SocksSocketImpl.javahaps84) in java.net.Socket.connect (Socket.java//42) in java.net.Socket.connect (Socket.java:492) in java.net.Socket. (Socket.javahaps89) in java.net.Socket. (Socket.java:232) in com.mysql.jdbc.StandardSocketFactory.connect (StandardSocketFactory.java:253) in com.mysql.jdbc.MysqlIO. (MysqlIO.java:292) ... 19 more SQLException: Communication error communication channel
The last packet the server sent successfully was 0 milliseconds ago. The driver did not receive any packets from the server. SQLState: 08S01 VendorError: 0
Process terminated by exit code 0
I literally don't know how to fix this error message. The database exists. Username and password exist. I have not added any tables to the database at present, but I do not think this could be a problem, since I only create the connection in the end ...
I can provide additional information if necessary. I feel like I've tried a lot. Does anyone know of any ways to get more information on how and why this fails?
Thanks for your help!:)
olive source share