Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help: Connecting MySQL Database to JTable

 
Bobby Johnson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone. I am trying to connect my MySQL database to a JTable in Eclipse. Here is a sample of the database code for the application:



Now, this program is for a desktop application, not a web application. I already added the classpath variable for the MySQL driver as follows:

1. Right click the name of the project folder.
2. Click on properties.
3. Click on Java Build Paths.
4. Click on JRE libraries tab.
5. Click the Add External JAR button
6. Browse and find the mysql-connector-java-5.1.7-bin .jar file
7. Click ok.

After I ran the program, I got this exception:


Unable to find and load driver
com.mysql.jdbc.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2120)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DamagedGoods$QueryTableModel.initDB(DamagedGoods.java:2897)
at DamagedGoods$QueryTableModel.<init>(DamagedGoods.java:2824)
at DamagedGoods.<init>(DamagedGoods.java:398)
at DamagedGoods.main(DamagedGoods.java:402)
Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:335)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2043)
... 9 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
... 10 more


Now my question is how can I get rid of this exception from my desktop application. Also, what is the default classpath location for the MySQL .JAR files for desktop application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic