WEB开发网      婵犻潧鍊婚弲顐︽偟椤栨稓闄勯柦妯侯槸閻庤霉濠婂骸浜剧紒杈ㄥ笚閹峰懘鎮╅崹顐ゆ殸婵炴垶鎸撮崑鎾趁归悩鐑橆棄闁搞劌瀛╃粋宥夘敃閿濆柊锕傛煙鐎涙ê鐏f繝濠冨灴閹啴宕熼鍡╀紘婵炲濮惧Λ鍕叏閳哄懎绀夋繛鎴濈-楠炪垽鎮归崶褍妲婚柛銊ュ缁傚秹鏁撻敓锟� ---闂佹寧娲╅幏锟�
开发学院数据库DB2 为 DB2 XML 数据开发 Java 应用程序 阅读

为 DB2 XML 数据开发 Java 应用程序

 2009-11-12 00:00:00 来源:WEB开发网 闂侀潧妫撮幏锟�闂佸憡鍨电换鎰版儍椤掑倵鍋撳☉娆嶄沪缂傚稄鎷�婵犫拃鍛粶闁靛洤娲ㄩ埀顒佺⊕閵囩偟绱為敓锟�闂侀潧妫撮幏锟�  闂佺ǹ绻楀▍鏇㈠极閻愬搫绾ч柕濠忕細閼割亜顪冪€n剙浠ф繛鍫熷灥椤曘儵顢欓悡搴ば�
核心提示: 清单 7. 利用 SQL 检索完整的 XML 文档 importjava.sql.*;...publicstaticvoidsimpleQuery(){PreparedStatementselectStmt=null;Stringquery=null,stringDoc=null;ResultS


清单 7. 利用 SQL 检索完整的 XML 文档

import java.sql.*; 
 . . . 
public static void simpleQuery() { 
 PreparedStatement selectStmt = null; 
 String query = null, stringDoc = null; 
 ResultSet rs = null; 
 int clientID = 1885; 
  
 try{ 
   // get a connection 
  Connection conn = Conn.getConn(); 
   
  // define, prepare, and execute the query 
  // this will retrieve all XML data for a specific client 
  query = "select contactinfo from clients where id = " + clientID 
  selectStmt = conn.prepareStatement(query); 
  rs = selectStmt.executeQuery(); 
 
  // check for results 
  if (rs.next() == false) { 
    System.out.println("Can't read document with id " + clientID); 
  } 
 
   // fetch XML data as a string and print the results 
  else { 
     stringDoc = rs.getString(1); 
     System.out.println(stringDoc); 
   } 
   . . . 
   conn.close(); 
  } 
  catch (Exception e) { . . . }   
} 

该程序输出一行数据,其中包含指定客户的所有 XML 联系信息。

尽管这里没有展示,但是也可以使用 XQuery 来检索一个或多个完整的 XML 文档,假设您不需要在 XQuery 中合并参数标志符的话。在本文后面,您将看到一个 Java 摘录,其中使用 XQuery 来检索 XML 数据。

上一页  4 5 6 7 8 9 10  下一页

Tags:DB XML 数据

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接