aspose file tools*
The moose likes JDBC and the fly likes Help:  Connecting MySQL Database to JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help:  Connecting MySQL Database to JTable" Watch "Help:  Connecting MySQL Database to JTable" New topic
Author

Help: Connecting MySQL Database to JTable

Bobby Johnson
Greenhorn

Joined: Jan 05, 2009
Posts: 3
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help: Connecting MySQL Database to JTable