Oracle Java存储的过程可通过JDBC访问Postgres和SQL Server

发布于 2025-02-11 17:32:20 字数 2027 浏览 0 评论 0原文

我正在开发以下Java类,该类与Oracle,PostgreSQL和SQL Server建立连接。

Here's the source:

import java.sql.*;

public class test {
public static void main (String[] args) {       
    try {
        Connection connORA = DriverManager.getConnection("jdbc:oracle:thin:@myoracleserver:1521/myschema", "user", "password");
        if (connORA != null) {
            System.out.println("Connected to ORACLE");
        }
        
        Connection connPGS = DriverManager.getConnection("jdbc:postgresql://IP.of.my.server:5432/mydbname","user","password");
        if (connPGS != null) {
            System.out.println("Connected to POSTGRES");
        }       

        Connection connSQS = DriverManager.getConnection("jdbc:sqlserver://IP.of.my.server;databaseName=mydbname" ,"user" ,"password");
        if (connSQS != null) {
            System.out.println("Connected to SQLSERVER");               
        }
    }
    catch (SQLException e) {
        System.err.println(e.getMessage()); 
    }
}
}

I successfully compile the class with (In $ORACLE_HOME/jdbc/lib/ I have added postgresql-42.3.3.jar and sqljdbc4-2.0.jar)

javac -cp :$ORACLE_HOME/jdbc/lib/* test.java

java -cp :$ORACLE_HOME/jdbc/lib/* test
Connected to ORACLE
Connected to POSTGRES
Connected to SQLSERVER

现在,我想知道是否可以将类加载到Oracle DB中以通过存储的过程调用Java,因此我想知道是否可以将类加载为JDBC:default:Connection:Connection:Connection:Connection :做以下操作:

loadjava -user myoracleuser/muoraclepassword@myoracleschema $ORACLE_HOME/jdbc/lib/postgresql-42.3.3.jar
loadjava -user myoracleuser/muoraclepassword@myoracleschema $ORACLE_HOME/jdbc/lib/sqljdbc4-2.0.jar
loadjava -user myoracleuser/muoraclepassword@myoracleschema test.java

存储过程的执行返回以下消息:

Connected to ORACLE    
No suitable driver found for jdbc:postgresql://IP.of.my.server:5432/mydbname

我已经开发了一些我通过Oracle商店过程正确加载和执行程序的类尝试不允许的东西。任何指向我正确道路上的建议都将受到赞赏

I am developing the below java class that makes connections to Oracle, PostgreSQL and SQL Server.

Here's the source:

import java.sql.*;

public class test {
public static void main (String[] args) {       
    try {
        Connection connORA = DriverManager.getConnection("jdbc:oracle:thin:@myoracleserver:1521/myschema", "user", "password");
        if (connORA != null) {
            System.out.println("Connected to ORACLE");
        }
        
        Connection connPGS = DriverManager.getConnection("jdbc:postgresql://IP.of.my.server:5432/mydbname","user","password");
        if (connPGS != null) {
            System.out.println("Connected to POSTGRES");
        }       

        Connection connSQS = DriverManager.getConnection("jdbc:sqlserver://IP.of.my.server;databaseName=mydbname" ,"user" ,"password");
        if (connSQS != null) {
            System.out.println("Connected to SQLSERVER");               
        }
    }
    catch (SQLException e) {
        System.err.println(e.getMessage()); 
    }
}
}

I successfully compile the class with (In $ORACLE_HOME/jdbc/lib/ I have added postgresql-42.3.3.jar and sqljdbc4-2.0.jar)

javac -cp :$ORACLE_HOME/jdbc/lib/* test.java

The execution of the class end with the expected output

java -cp :$ORACLE_HOME/jdbc/lib/* test
Connected to ORACLE
Connected to POSTGRES
Connected to SQLSERVER

Now I am wondering if it is possible to load the class in Oracle DB in order to call the Java via stored procedure so I change the Oracle connection string in jdbc:default:connection: and do as follows:

loadjava -user myoracleuser/muoraclepassword@myoracleschema $ORACLE_HOME/jdbc/lib/postgresql-42.3.3.jar
loadjava -user myoracleuser/muoraclepassword@myoracleschema $ORACLE_HOME/jdbc/lib/sqljdbc4-2.0.jar
loadjava -user myoracleuser/muoraclepassword@myoracleschema test.java

The execution of the stored procedure returns these messages:

Connected to ORACLE    
No suitable driver found for jdbc:postgresql://IP.of.my.server:5432/mydbname

I already develop some class that I correctly load and exec via Oracle store procedure but I am quite new with Java and probably I am missing something obvious or trying something not allowed. Any suggestion that point me in the right path will be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文