Db2 数据库选出CLOB 里面的内容

在db2 server上,用sql 语句选 clob 字段,果里面的数据很大,有3M 左右大小的内容,
直接选不出来。
方法一:
写个一个java 程序,选出的结果放到文件中。
package com.ibm;

import java.io.*;
import java.sql.*;

public class TestConnDb2 {
	public static void main(String[] args) {
		try {
			Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
			String url = "jdbc:DB2:oi9ods";
			String user = "youruser";
			String password = "yourpassword";
			Connection conn = DriverManager.getConnection(url, user, password);
			String sql = "select pricexml from price.wwprtxml where id = 34851 with ur";
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
			if (rs.next()) {
				System.out.println("test start");
				Writer output = null;
				String text = rs.getString(1);
				File file = new File("xml.txt");
				output = new BufferedWriter(new FileWriter(file));
				output.write(text);
				output.close();
				System.out.println("test end!");
			}
			conn.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}



方法二:
db2 connect to oi9ods user youruser using yourpassword
db2 export to wwprt.del of del modified by lobsinfile messages wwprt.msg select pricexml from price.wwprtxml where id = 34851 with ur

可是不知道为什么,用export 方法导出的文件的内容有问题,里面包含2遍 字段里面的内容,暂时还可以用,把重复的内容去掉,随后再仔细研究一下原因。

猜你喜欢

转载自wangyl93-dl-cn.iteye.com/blog/1468954