繁体   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