Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

New to JDBC, Connection Error

843859Jul 26 2005 — edited Aug 5 2005
When attempting to connect to a database on a secondary machine on the network I get the following error
---
Cannot connect to database server
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.NoRouteToHostException: No route to host: connect

STACKTRACE:

java.net.SocketException: java.net.NoRouteToHostException: No route to host: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:283)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2541)
at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at db.main(db.java:15)


** END NESTED EXCEPTION **



Last packet sent to the server was 40 ms ago.

------

My code that I am using for this is
import java.sql.*;

public class db {

	public static void main(String[] args) 
	{
		Connection conn = null;

        try
        {
            String userName = "myusername";
            String password = "mypass";
            String url = "jdbc:mysql://foobar/fooooo";
            Class.forName ("com.mysql.jdbc.Driver").newInstance ();
            conn = DriverManager.getConnection (url, userName, password);
            System.out.println ("Database connection established");
        }
        catch (Exception e)
        {
            System.err.println ("Cannot connect to database server");
            System.out.println(e);
        }
        finally
        {
            if (conn != null)
            {
                try
                {
                    conn.close ();
                    System.out.println ("Database connection terminated");
                }
                catch (Exception e) { /* ignore close errors */ }
            }
        }
		
	}
}

Comments

john16384
The docs donot say anything about the resource management done by Stages. Comparing it with Swing is useless since they're completely different.

The reason for dispose() in Swing was that even when your code does not refer to a JFrame anymore, there are still native resources which refer to the JFrame which will keep it from being garbage collected. Dispose() releases those resources.

In JavaFX the distinction between close and dispose is probably no longer needed because using weak refs they can track when the Stage is no longer referenced anymore and then release all resources associated with it (if it works that way at all).

So, close() would 'hide' the Stage, and when it gets garbage collected an automatic 'dispose' occurs. If Stages needed any further special treatment I would expect a mention in the docs.
shakir.gusaroff
Hi. The JavaFX lifecycle is different than the Swing lifecycle.
In JavaFX when you close the last window or the application calls Platform.exit() the JavaFX runtime calls Application.stop()
to prepare for application exit and destroys resources.
For more info take a look at: http://docs.oracle.com/javafx/2/api/javafx/application/Application.html
952782
Thanks guys.. you both are right! well atleasat!
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 2 2005
Added on Jul 26 2005
3 comments
2,407 views