xml保存入DB2数据库 package X2R2D;
import java.io.*;
import java.sql.*;
public class xml2db2 {
private Connection con = null;
private PreparedStatement pstat=null;
public boolean openConn() throws Exception {
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbc...
package X2R2D;
import java.io.*;
import java.sql.*;
public class xml2db2 {
private Connection con = null;
private PreparedStatement pstat=null;
public boolean openConn() throws Exception {
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try{
Class.forName("com.ibm.db2.jcc.DB2Driver");
}catch(Exception e){
System.out.println("驱动失败");
} String url="jdbc:db2://××××××";
数据库名
String user="******";
//用户名
String password="******";
//密码
con=DriverManager.getConnection(url, user, password);
return true;
} catch(SQLException e) { e.printStackTrace();
return false;
} } public void getInsert() throws Exception {
pstat= con.prepareStatement("INSERT INTO xmltable VALUES (?,?)");
String xmlfile="c:/1.xml";
String xmlString = "";
从文件中读取XML数据,构造成String类型的数据try{
InputStreamReader isr
= new InputStreamReader(new FileInputStream(xmlfile), "UTF-8");
//注意编码
BufferedReader in = new BufferedReader(isr);
String line =null;
while((line = in.readLine()) !=null) { xmlString += line;
} in.close();
pstat.setInt(1, 2);
pstat.setString(2, xmlString);
pstat.executeUpdate();
} public boolean closeConn()
throws SQLException { con.close();
return true;
} public static void main(String[] args)throws
Exception { xml2db2 db=new xml2db2();
db.openConn();
db.getInsert();
db.closeConn();
System.out.println("XML成功写入DB2数据库");
} }
本文档为【xml保存入DB2数据库】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。