java db2 import_java 执行db2 的export import

需要用代码备份db2的表,java不能直接执行,google发现要用ADMIN_CMD这个存储过程执行export,db2v8.1要打到补丁9以上才会有 ADMIN_CMD,高版本不用打补丁.db2v8.1不打补丁会报(COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0444N  例程 "ADMIN_CMD"(特定名称 "SQL100224161758450")是用库或路径 "\SYSPROC.ADMIN_CMD" 中的代码以及不能存取的函数 "SYSPROC.ADMIN_CMD" 来实现的。原因代码:"4"。  SQLSTATE=42724)错误

以下是官网例子

import java.io.*;

import java.lang.*;

import java.util.*;

import java.sql.*;

class AdmCmdExport

{

public static void main(String argv[])

{

Connection con = null;

int rows_exported;

String msg_retrieval = null;

String msg_removal = null;

String sqlcode = null;

String msg = null;

CallableStatement callStmt1 = null;

ResultSet rs1 = null;

PreparedStatement stmt1 = null;

ResultSet rs2 = null;

CallableStatement callStmt2 = null;

if (argv.length < 1)

{

System.out.println("\n Usage : java AdmCmdExport ");

}

else

{

try

{

// initialize DB2Driver and establish database connection.

COM.ibm.db2.jdbc.app.DB2Driver db2Driver =

(COM.ibm.db2.jdbc.app.DB2Driver)

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();

con = DriverManager.getConnection("jdbc:db2:SAMPLE");

System.out.println("HOW TO PERFORM EXPORT USING ADMIN_CMD.\n");

// prepare the CALL statement for OUT_LANGUAGE

String sql = "CALL SYSPROC.ADMIN_CMD(?)";

callStmt1 = con.prepareCall(sql);

String param = "export to "+ argv[0] + "org_ex.ixf ";

param = param + "of ixf messages on server select * from org" ;

// set the imput parameter

callStmt1.setString(1, param);

System.out.println("CALL ADMIN_CMD('" + param + "')");

// execute export by calling ADMIN_CMD

callStmt1.execute();

rs1 = callStmt1.getResultSet();

// retrieve the resultset

if( rs1.next())

{

// the numbers of rows exported

rows_exported = rs1.getInt(1);

// retrieve the select stmt for message retrival

// containing SYSPROC.ADMIN_GET_MSGS

msg_retrieval = rs1.getString(2);

// retrive the stmt for message cleanup

// containing CALL of SYSPROC.ADMIN_REMOVE_MSGS

msg_removal = rs1.getString(3);

// display the output

System.out.println("Total number of rows exported  : " + rows_exported);

System.out.println("SQL for retrieving the messages: " + msg_retrieval);

System.out.println("SQL for removing the messages  : " + msg_removal);

}

stmt1 = con.prepareStatement(msg_retrieval);

System.out.println("\n" + "Executing " + msg_retrieval);

// message retrivel

rs2 = stmt1.executeQuery();

// retrieve the resultset

while(rs2.next())

{

// retrieve the sqlcode

sqlcode = rs2.getString(1);

// retrieve the error message

msg = rs2.getString(2);

System.out.println("Sqlcode : " +sqlcode);

System.out.println("Msg     : " +msg);

}

System.out.println("\nExecuting " + msg_removal);

callStmt2 = con.prepareCall(msg_removal);

// executing the message retrivel

callStmt2.execute();

}

catch(Exception e)

{

JdbcException jdbcExc = new JdbcException(e);

jdbcExc.handle();

}

finally

{

try

{

// close the statements

callStmt1.close();

callStmt2.close();

stmt1.close();

// close the resultsets

rs1.close();

rs2.close();

// roll back any changes to the database made by this sample

con.rollback();

// close the connection

con.close();

}

catch (Exception x)

{

System.out.print("\n Unable to Rollback/Disconnect ");

System.out.println("from 'sample' database");

}

}

}

} // main

} // AdmCmdExport

官网例子地址[http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.sample.doc/doc/java_jdbc/s-AdmCmdExport-java.htm]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值