簡體   English   中英

如何使用jdbc和java-swing從特定列檢索完整的xml(DataType as XMLTYPE)

[英]How to retrieve the complete xml (DataType as XMLTYPE) from the specific column using jdbc and java-swing

我有一個名為student的表名,在該表中我有一列名為student_xml,另一列是student_id

所以我寫了下面的代碼來從db中檢索數據。

從student_id ='2301C8'的學生中選擇student_xml;

當我在sql server中執行此查詢時,它的工作正常,但是當我嘗試使用swing應用程序(java數據庫連接)獲取空值時。

String strxa = tfx1.getText(); //here i will get the student id from user.

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//host:1521/service","username","pwd");
    Statement st =con.createStatement();
    String str3 ="select student_xml  from student where student_id='"+strxa+"'";

    System.out.println(str3);

    ResultSet rs = st.executeQuery(str3);
    System.out.println(str3);

   if (rs.next()) {

            XMLType poxml = (XMLType)rs.getObject(1);
            System.out.println(poxml); //when i try to print this no output in console
            String poString =poxml.getStringVal();
            System.out.println(poString); when i try to print this no output in console


            //Sets Records in TextFields.
            area.setText(poString);


        }

有沒有其他方法我們必須遵循XMLTYPE數據並在文本區域顯示這些東西?

以下是從XMLTYPE結果集接收數據的正確代碼

  1. 添加以下import - import oracle.xdb.XMLType;

  2. 使用以下while循環,它將檢索XMLTYPE並將其存儲在名為poString的字符串中。

      while(rs.next()) { // get the XMLType XMLType poxml = (XMLType)rs.getObject(1); // get the XML as a string... String poString = poxml.getStringVal(); } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM