日期:2014-05-16 浏览次数:20691 次
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(); } } }