自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

java XML成功存入DB2 代碼的實(shí)際操作步驟

數(shù)據(jù)庫
我們今天是要和大家一起分享的是java XML成功存入DB2 代碼的實(shí)際操作步驟,你如果對(duì)其有興趣的話你就可以點(diǎn)擊以下的文章進(jìn)行觀看了。

java XML成功存入DB2 代碼的實(shí)際操作步驟,假如你在實(shí)際操作中java XML成功存入DB2 代碼的實(shí)際操作,但是你卻不知道對(duì)其如何正確的對(duì)其進(jìn)行操作的話,那么以下的文章對(duì)你而言一定是良師益友。

1、首先現(xiàn)在DB2上建立表:

 

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

2、執(zhí)行下面代碼把c盤下的XML文件存入數(shù)據(jù)庫

  1. package X2R2D;  
  2. import java.io.*;  
  3. import java.sql.*;  
  4. public class xml2db2   
  5. {  
  6. private Connection con = null;  
  7. private PreparedStatement pstat=null;  
  8. public boolean openConn() throws Exception  
  9. {  
  10. try{  
  11. //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
  12. try{Class.forName("com.ibm.db2.jcc.DB2Driver");}catch(Exception e){System.out.println("驅(qū)動(dòng)失敗");}  
  13. String url="jdbc:db2://××××××"

數(shù)據(jù)庫名

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

 

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

 

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

從文件中讀取XML數(shù)據(jù),構(gòu)造成String類型的數(shù)據(jù)try{

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

注意編碼

  1. BufferedReader in = new BufferedReader(isr);   
  2. String line =null;  
  3. while((line = in.readLine()) !=null)   
  4. {  
  5. xmlString += line;   
  6. }   
  7. in.close();   
  8. pstat.setInt(1, 2);   
  9. pstat.setString(2, xmlString);   
  10. pstat.executeUpdate();  
  11. }  
  12. public boolean closeConn() throws SQLException  
  13. {  
  14. con.close();  
  15. return true;  
  16. }  
  17. public static void main(String[] args)throws Exception  
  18. {  
  19. xml2db2 db=new xml2db2();  
  20. db.openConn();  
  21. db.getInsert();  
  22. db.closeConn();  
  23. System.out.println("XML成功寫入DB2數(shù)據(jù)庫");  
  24. }  
  25. }  

以上的相關(guān)內(nèi)容就是對(duì)java XML成功存入DB2 代碼的介紹,望你能有所收獲。

 

【編輯推薦】

  1. DB2數(shù)據(jù)庫開發(fā)與PostgreSQL開發(fā)中的異同點(diǎn)
  2. DB2用戶密碼修改與備份恢復(fù)的正確應(yīng)用
  3. DB2表格操作技巧之導(dǎo)出LOB數(shù)據(jù),很簡(jiǎn)單!
  4. DB2未使用索引的查找方案描述
  5. DB2數(shù)據(jù)庫性能理解的主要誤區(qū)有哪些?如何避免?
責(zé)任編輯:佚名 來源: TechTarget中國
相關(guān)推薦

2010-08-05 13:45:57

存入DB2 代碼

2010-08-03 09:32:19

DB2在線備份

2010-07-27 11:20:02

DB2打補(bǔ)丁

2010-08-03 09:44:42

DB2在線增量備份

2010-08-05 14:34:26

DB2存儲(chǔ)過程

2010-08-12 17:36:48

DB2還原某個(gè)表空間

2010-08-05 11:29:04

java DB2

2010-08-03 13:56:11

DB2表復(fù)制

2010-07-28 08:58:50

DB2并行索引

2010-08-12 09:06:30

DB2數(shù)據(jù)庫自動(dòng)備份

2010-08-03 09:49:58

DB2恢復(fù)數(shù)據(jù)庫

2010-08-12 09:25:22

DB2數(shù)據(jù)庫復(fù)原

2010-08-17 13:25:39

DB2恢復(fù)刪除表

2010-07-30 13:45:17

執(zhí)行DB2

2010-08-12 14:03:24

DB2恢復(fù)誤刪除表

2010-08-04 09:29:32

2010-08-12 10:22:21

DB2定期自動(dòng)備份

2010-07-30 14:21:10

DB2數(shù)據(jù)集

2010-08-04 11:12:09

DB2命令執(zhí)行

2010-08-05 13:10:11

DB2代碼
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)