java XML成功存入DB2 代码的实际操作步骤

数据库
我们今天是要和大家一起分享的是java XML成功存入DB2 代码的实际操作步骤,你如果对其有兴趣的话你就可以点击以下的文章进行观看了。

java XML成功存入DB2 代码的实际操作步骤,假如你在实际操作中java XML成功存入DB2 代码的实际操作,但是你却不知道对其如何正确的对其进行操作的话,那么以下的文章对你而言一定是良师益友。

1、首先现在DB2上建立表:

 

Create table xmltable(id int , content xml); 
  • 1.

2、执行下面代码把c盘下的XML文件存入数据库

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://××××××"
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

数据库名

String user="******"; //用户名

 

String password="******"; //密码

 

con=DriverManager.getConnection(url, user, password);  
return true;  
}  
catch(SQLException e)  
{  
e.printStackTrace();  
return false;  
}   
}  
public void getInsert() throws Exception  
{  
pstatcon.prepareStatement("INSERT INTO xmltable VALUES (?,?)");  
String xmlfile="c:/1.xml";  
String xmlString = ""
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

从文件中读取XML数据,构造成String类型的数据try{

InputStreamReader isr = new InputStreamReader(new FileInputStream(xmlfile), "UTF-8");  
  • 1.

注意编码

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数据库");  
}  
}  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

以上的相关内容就是对java XML成功存入DB2 代码的介绍,望你能有所收获。

 

【编辑推荐】

  1. DB2数据库开发与PostgreSQL开发中的异同点
  2. DB2用户密码修改与备份恢复的正确应用
  3. DB2表格操作技巧之导出LOB数据,很简单!
  4. DB2未使用索引的查找方案描述
  5. DB2数据库性能理解的主要误区有哪些?如何避免?
责任编辑:佚名 来源: TechTarget中国
相关推荐

2010-08-05 13:45:57

存入DB2 代码

2010-08-03 09:32:19

DB2在线备份

2010-07-27 11:20:02

DB2打补丁

2010-08-03 09:44:42

DB2在线增量备份

2010-08-05 14:34:26

DB2存储过程

2010-08-12 17:36:48

DB2还原某个表空间

2010-08-05 11:29:04

java DB2

2010-08-03 13:56:11

DB2表复制

2010-07-28 08:58:50

DB2并行索引

2010-08-12 09:06:30

DB2数据库自动备份

2010-08-03 09:49:58

DB2恢复数据库

2010-08-12 09:25:22

DB2数据库复原

2010-08-17 13:25:39

DB2恢复删除表

2010-07-30 13:45:17

执行DB2

2010-08-04 09:29:32

2010-08-12 10:22:21

DB2定期自动备份

2010-08-12 14:03:24

DB2恢复误删除表

2010-07-30 14:21:10

DB2数据集

2010-08-04 11:12:09

DB2命令执行

2010-08-05 13:10:11

DB2代码
点赞
收藏

51CTO技术栈公众号