如何使用防火墙限制将applet连接到oracle数据库

时间:2015-03-09 08:09:50

标签: java database oracle applet

我创建了一个我需要连接到oracle数据库的java applet。出于安全原因,我的问题是从中创建oracle数据库的服务器受防火墙保护,以防止直接连接数据库。我有数据库IP地址和运行数据库的端口以及服务名称,但我不知道如何连接到该服务器以便我可以访问数据库。这是我尝试连接数据库的示例源代码。

String dbip="xx.xx.xx.xx";
        String dbport="1523";
        String serviceName="servicenamexample";
        try {
            url="jdbc:oracle:thin:@(description=(address_list="+
                     "(address=(protocol=tcp)(host="+dbip+")(port="+dbport+")))"+
                     "(source_route=yes)"+
                     "(connect_data=(INSTANCE_NAME="+serviceName+")))";
            password="mypass";
            username="myusername";
            OracleDataSource odbc=new OracleDataSource();
            odbc.setURL(url);
            odbc.setPassword(password);
            odbc.setUser(username);
            conn=odbc.getConnection();
            System.out.println("connection established !");

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

这就是错误。

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
    at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:297)
    at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:221)

0 个答案:

没有答案