java - I found a net connection error while using localhost in jdbc -


I have written this program to connect to my computer which is on the same computer but every time I have a pure connection Error found. Com.mysql.jdbc.CommunicationsException: communication link failure due to the built-in exception:

  import java.sql *; Public class demo {public static zero main (string [] args) {try {class.forName ("com.mysql.jdbc.Driver"); Connection Connection = DriverManager.getConnection ("jdbc: mysql: //127.0.0.1: 3306 / db", "user name", "pwd"); Statement stmt = connection.createStatement (); String str = "show tab"; Result result result = stmt.executeQuery (str); While (resultSet.next ()) {System.out.println (resultSet.getString (1)); }} Hold (exception e) {e.printStackTrace (); }}}  

My stacktrace is: -

  com.mysql.jdbc.CommunicationsException: communication link failure due to the underlying exception: ** BEGIN nested exception ** java.net.ConnectException Message: Connection refused: Connect STACKTRACE: java.net.ConnectException: Connection refused: Connect to java.net. Connect to Java.net.PlainSocketImpl.do (Basic method) on Java.net.PlainSocketImpl.connectToAddress (unknown source) PlainSocketImpl.doConnect (unknown source) java.net.PlainSocketImpl.connect (unknown source) java.net.SocksSocketImpl On .connect (unknown source) at java.net.Socket.connect (unknown source) on Java. Java.net.Socket on Java.net.Socket & net.ocket.net.ocket (unknown source) & Lt; Init & gt; (Unknown source) com.mysql.jdbc.StandardSocketFactory.connect on net.socket.connect (unknown source) Com.mysql.jdbc.MysqlIO & Lt; Init & gt; (MySqlIO.java, 2007) at com.mysql.jdbc.Connection.cr StandardSocketFactory.java:256) eateNewIO (connection.java:2771) at Com.mysql.jdbc.Connection. & Lt; Init & gt; (Connection. Java 1555) at com.mysql.jdbc.NonRegisteringDriver.connect (NonRegisteringDriver.java amax85) at java.sql. DriverManager.getConnection (unknown source) at java.sql.DriverManager.getConnection (unknown source) on demo.main (demo.java: 8) ** Expiration of death death ** The last packet sent to server was 0 ms ago. Com.mysql.jdbc.Connection at Com.mysql.jdbc.Connection.createNewIO & Lt; Init & gt; (Connection.java 1555) on com.mysql.jdbc.NonRegisteringDriver.connect (nonRegisteringDriver.java.sql at java.sql.DriverManager.getConnection (unknown source) on java.sql.DriverManager.getConnection (unknown source) demo.main DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / dbname", "username", "user name" , "Password");  

If it has not been sorted, you can install MySQL and open MySQL Notifier and check whether or not the check server is running, if it does not start And then execute your program Do Mitigation effort.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -