Java銜接並操作Sedna XML數據庫的辦法。本站提示廣大學習愛好者:(Java銜接並操作Sedna XML數據庫的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是Java銜接並操作Sedna XML數據庫的辦法正文
本文實例講述了Java銜接並操作Sedna XML數據庫的辦法。分享給年夜家供年夜家參考。詳細剖析以下:
Sedna 是一個原生的XML數據庫,供給了全功效的焦點數據庫辦事,包含耐久化存儲、ACID事務、索引、平安、熱備、UTF8等。完成了 W3C XQuery 標准,支撐全文搜刮和節點級其余更新操作。
import ru.ispras.sedna.driver.*; public class SednaClient { public static void main(String args[]) { SednaConnection con = null; try { /* Get a connection */ con = DatabaseManager.getConnection("localhost", "testdb", "SYSTEM", "MANAGER"); /* Begin a new transaction */ con.begin(); /* Create statement */ SednaStatement st = con.createStatement(); /* Load XML into the database */ System.out.println("Loading data ..."); boolean res; res = st.execute("LOAD 'C:/region.xml' 'region'"); System.out.println("Document 'region.xml' "+ "has been loaded successfully"); /* Execute query */ System.out.println("Executing query"); res = st.execute("doc('region')/*/*"); /* Print query results */ printQueryResults(st); /* Remove document */ System.out.println("Removing document ..."); res = st.execute("DROP DOCUMENT 'region'"); System.out.println("Document 'region' " + "has been dropped successfully"); /* Commit current transaction */ con.commit(); } catch(DriverException e) { e.printStackTrace(); } finally { /* Properly close connection */ try { if(con != null) con.close(); } catch(DriverException e) { e.printStackTrace(); } } } /* Pretty printing for query results */ private static void printQueryResults(SednaStatement st) throws DriverException { int count = 1; String item; SednaSerializedResult pr = st.getSerializedResult(); while ((item = pr.next()) != null) { System.out.println(count + " item: " + item); count++; } } }
願望本文所述對年夜家的java法式設計有所贊助。