0

I've looked all over and tried everything I've been able to find on this so I'm making a post in case my issue is something strange.

MySQL workbench can use the server for queries and updates just fine. The notifier shows the server is running.

I've tried using Eclipse Juno and Kepler and got eclipse SQL State: 08S01 error 0. Zero packets were sent successfully and there was no response from the server. I redownloaded Connector/J to make sure there wasn't an error from a download hiccup. Didn't improve.

I changed to Netbeans to make sure it wasn't just Eclipse and something on my system. No successful packets sent and nothing received.

I tested to make sure the server was on and the correct port was being used by telnet in command prompt and as expected it asks for password input like it should. I used Wire Shark to see what the packet data looked like. It looked like the server was listening on the correct port and MySQL workbench was using the right port.

I'm at a loss for what is wrong. I even updated to Windows 7 to make sure it wasn't a driver authentication issue with Vista.

I used this code in NetBeans:

    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;

    public class MySQLTest {
       public static void main(String[] args)
       {
                   try {
               Class.forName("com.mysql.jdbc.Driver").newInstance();
               System.out.println("1");
               Connection con =        DriverManager.getConnection("jdbc:mysql://127.0.0.0:3306/", "root", "wonderwoman");
                 System.out.println("2");
                 con.close();
               System.out.println("We made it!");
           } catch (SQLException ex) {
               Logger.getLogger(MySQLTest.class.getName()).log(Level.SEVERE, null, ex);
           } catch (ClassNotFoundException ex) {
               Logger.getLogger(MySQLTest.class.getName()).log(Level.SEVERE, null, ex);
           } catch (InstantiationException ex) {
               Logger.getLogger(MySQLTest.class.getName()).log(Level.SEVERE, null, ex);
           } catch (IllegalAccessException ex) {
               Logger.getLogger(MySQLTest.class.getName()).log(Level.SEVERE, null, ex);
           }
       }
    }

And eventually received this:

Oct 22, 2013 8:59:20 PM rad.MySQLTest main SEVERE: null com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:357)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2482)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2519)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2304)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at rad.MySQLTest.main(MySQLTest.java:21)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:241)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:307)
    ... 15 more

What else should I try? It looks like it's getting to the server and than everything is just bouncing off. I've turned off my firewall, I'm not using a proxy, kind of pulling my hair out here.

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
SilentChaos
  • 1
  • 1
  • 2
  • append your database name to the connection string and try e.g. "jdbc:mysql://127.0.0.1:3306/databasename" – Thusitha Thilina Dayaratne Oct 23 '13 at 02:34
  • Where is your db name.. Add your db name to connection string then it will work – Kanagaraj M Oct 23 '13 at 02:37
  • I found out the problem. I had an old version of java that wasn't being removed when I updated and there was a conflict when the driver was trying to use the wrong version of java. Also, NetBeans doesn't seem to send user names and passwords in the same way Eclipse does, so I had to use the 'getConnection(url, username, password)' format. This was discovered in a different program using the same connection type, but it's important for whatever reason. – SilentChaos Oct 30 '13 at 05:52

5 Answers5

0

I think you are running mysql on your local machine if so append your database name to the connection string and try e.g. "jdbc:mysql://127.0.0.1:3306/databasename" or try "jdbc:mysql://localhost:3306/databasename"
You are using 127.0.0.0 as your ip address but normally localhost is 127.0.0.1 not 127.0.0.0

  • That was a mistake at that time; but it had been 'localhost' and '127.0.0.1' in other attempts. It was not the issue. MySQL has pretty crap-tacular user/help manuals. I am unimpressed to say the least. Thanks for trying to help, though. – SilentChaos Oct 30 '13 at 05:57
0

Add the MySql_connetor.bin file to your project Library, then clean and build, and run.

David
  • 208,112
  • 36
  • 198
  • 279
samira
  • 1
0

I just do a quick search and see this video tutorial, maybe you do something wrong in step by step. Hope it 's helpful for your need http://magentoexpertforum.com/showthread.php/10268-Connect-Netbean-to-MySQL

Phuc
  • 143
  • 1
  • 7
0

Hi I just had the exact same problem, up until now my MySQL server was being connected to netbeans fine, then all of a sudden it stopped working. I checked my my.config file in the bin folder and for some reason the port had changed from 3306 to 6033, so you can either re-register your MySQL with the new port number, or change the port number in the config file.

0

Try this code :

try {
  Class.forName("java.sql.Driver");
  Connection con = 
  DriverManager.getConnection("jdbc:mysql://localhost/db_name","username","password");
  Statement stmt = con.createStatement();
  ///your furthercode acc. to your project
}
catch(Exception e) {
  JOptionPane.showMessageDialog(null,e.getMessage());
}
Chrisvin Jem
  • 3,940
  • 1
  • 8
  • 24
  • 2
    Hi, welcome to stackoverflow, try not to just provide code but to also provide additional information such as what your code does or what was initially wrong. – Chrisvin Jem Jul 13 '19 at 20:45