将 oracle 表复制到 DB2

发布于 2024-12-06 01:56:31 字数 71 浏览 1 评论 0原文

我想访问 DB2 中的 Oracle 表(类似于从 DB2 到 Oracle 的 DBlink)。如有任何帮助,我们将不胜感激。

I want to access oracle tables in DB2(something like DBlink from DB2 to oracle).Any help is appreciated.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荭秂 2024-12-13 01:56:31

您可以使用 db2 联合。 此处有一个链接。

You can use db2 federation. One link is here.

中二柚 2024-12-13 01:56:31

Oracle 有一个称为异构服务的功能,它允许我们在 Oracle 数据库和非 Oracle 数据库(包括 DB2)之间建立链接。 了解更多信息

Oracle has a feature called Heterogeneous Services which allows us to build links between Oracle databases and non-Oracle databases, including DB2. Find out more.

谎言 2024-12-13 01:56:31
import com.ibm.db2.jcc.am.gc;
import com.ibm.db2.jcc.t2zos.s;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import static org.omg.IOP.ENCODING_CDR_ENCAPS.value;

public class automateExport {

    static String value;

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        // ResultSet rs = null;
        String table_name;
        Integer temp = 0;
        Integer temp1 = 0;
        Integer temp2 = 1;
        String column_name = null;
        String tableName = null;
        String columnType = null;
        int precision = 0;

        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection codal = DriverManager.getConnection("jdbc:oracle:thin:@192.168.01.53:1521:orcl", "NAVID",
                "oracle");

        StringBuilder sb = new StringBuilder(1024);

        Connection DB2 = getConnection();
        String sql = "SELECT TABSCHEMA,TABNAME,COLNAME,TYPENAME,LENGTH FROM SYSCAT.COLUMNS WHERE TABSCHEMA NOT LIKE 'SYS%' ";
        PreparedStatement mainStmt = DB2.prepareStatement(sql);
        ResultSet rs = mainStmt.executeQuery();
        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();
        String str1 = "ADMIN2";

        while (rs.next()) {

            table_name = rs.getString(2);

            if (table_name.equalsIgnoreCase(str1)) {
                if (temp1 == 0) {

                    sb.append("create table").append(" ");
                    sb.append(table_name).append("( ");
                    if (temp2 == 0) {
                        sb.append(" ").append(column_name).append(" ").append(columnType);
                        if (precision != 0) {
                            sb.append("( ").append(precision).append(" )");
                            sb.append(", ");

                        }
                    }

                    temp1 = 1;
                    temp = 1;
                }

                if (temp == 0) {
                    sb.append(table_name).append("(");
                    temp = 1;
                }
                column_name = rs.getString(3);
                columnType = rs.getString(4);
                sb.append(" ").append(column_name).append(" ").append(columnType);
                precision = rs.getInt(5);
                if (precision != 0) {
                    sb.append("( ").append(precision).append(" )");
                    sb.append(", ");
                }
            } else {
                temp2 = 0;
                sb.replace(sb.length() - 2, sb.length(), "");
                sb.append(" )");
                temp1 = 0;
                str1 = str1.replaceAll(str1, table_name);
                column_name = rs.getString(3);
                columnType = rs.getString(4);
                precision = rs.getInt(5);
                String sql2 = sb.toString();
                PreparedStatement m = codal.prepareStatement(sql2);
                m.executeUpdate();
                sb.delete(0, sb.length());
            }
        }
        codal.close();
        DB2.close();
/*


        }


    private static Connection getConnection() throws ClassNotFoundException, SQLException {
        Class.forName("COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver");
        Connection connection
                = DriverManager.getConnection("jdbc:db2://localhost:50000/navid", "navid", "oracle");
        return connection;

    }

}
import com.ibm.db2.jcc.am.gc;
import com.ibm.db2.jcc.t2zos.s;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import static org.omg.IOP.ENCODING_CDR_ENCAPS.value;

public class automateExport {

    static String value;

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        // ResultSet rs = null;
        String table_name;
        Integer temp = 0;
        Integer temp1 = 0;
        Integer temp2 = 1;
        String column_name = null;
        String tableName = null;
        String columnType = null;
        int precision = 0;

        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection codal = DriverManager.getConnection("jdbc:oracle:thin:@192.168.01.53:1521:orcl", "NAVID",
                "oracle");

        StringBuilder sb = new StringBuilder(1024);

        Connection DB2 = getConnection();
        String sql = "SELECT TABSCHEMA,TABNAME,COLNAME,TYPENAME,LENGTH FROM SYSCAT.COLUMNS WHERE TABSCHEMA NOT LIKE 'SYS%' ";
        PreparedStatement mainStmt = DB2.prepareStatement(sql);
        ResultSet rs = mainStmt.executeQuery();
        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();
        String str1 = "ADMIN2";

        while (rs.next()) {

            table_name = rs.getString(2);

            if (table_name.equalsIgnoreCase(str1)) {
                if (temp1 == 0) {

                    sb.append("create table").append(" ");
                    sb.append(table_name).append("( ");
                    if (temp2 == 0) {
                        sb.append(" ").append(column_name).append(" ").append(columnType);
                        if (precision != 0) {
                            sb.append("( ").append(precision).append(" )");
                            sb.append(", ");

                        }
                    }

                    temp1 = 1;
                    temp = 1;
                }

                if (temp == 0) {
                    sb.append(table_name).append("(");
                    temp = 1;
                }
                column_name = rs.getString(3);
                columnType = rs.getString(4);
                sb.append(" ").append(column_name).append(" ").append(columnType);
                precision = rs.getInt(5);
                if (precision != 0) {
                    sb.append("( ").append(precision).append(" )");
                    sb.append(", ");
                }
            } else {
                temp2 = 0;
                sb.replace(sb.length() - 2, sb.length(), "");
                sb.append(" )");
                temp1 = 0;
                str1 = str1.replaceAll(str1, table_name);
                column_name = rs.getString(3);
                columnType = rs.getString(4);
                precision = rs.getInt(5);
                String sql2 = sb.toString();
                PreparedStatement m = codal.prepareStatement(sql2);
                m.executeUpdate();
                sb.delete(0, sb.length());
            }
        }
        codal.close();
        DB2.close();
/*


        }


    private static Connection getConnection() throws ClassNotFoundException, SQLException {
        Class.forName("COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver");
        Connection connection
                = DriverManager.getConnection("jdbc:db2://localhost:50000/navid", "navid", "oracle");
        return connection;

    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文