使jdbc连接到oracle apex db

时间:2015-10-12 05:27:15

标签: java oracle jdbc oracle-apex

我正在尝试连接到oracle apex数据库。我的classpath中有ojdbc.jar。这是我的示例代码。

  public class ConnectionDAO {
    String database = "demo";
    String user = "myusername";
    String password = "somepwd";
    String host = "https://apex.oracle.com/"; // By default
    String port ="8086";
    private Connection con;

    public Connection connect() {
        try {

            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

            con = DriverManager.getConnection("jdbc:oracle:thin:@//" + host + ":" + port +"/"+database+"?user="+user+"&password="+password);
            //con = DriverManager.getConnection("jdbc:oracle://" + host + "/"
                //  + database + "?user=" + user + "&password=" + password);
            // Set connectionStatus
            System.out.println("Connected");

            return con;
        } catch (Exception E) {
            System.out.println("Not Connected");
            E.printStackTrace();
            return null;
        }
    }


}

但它提供了以下异常

java.sql.SQLException: invalid arguments in call
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:208)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:236)
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 java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:233)
at com.lister.dao.ConnectionDAO.connect(ConnectionDAO.java:19)
at com.lister.quiz.Test.main(Test.java:8)

我是oracle apex的新手。我浏览了它,但没有得到满意的解决方案。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:-1)

apex应用程序存储在数据库中。 您需要获取引用数据库的主机和端口以建立jdbc连接。 通常默认的db端口是1521。