从SQL数据库访问java中xml命名空间标记的值

时间:2011-09-20 05:26:25

标签: java mysql sql xml

您好。我编写了一个java代码,用于在单独的xml文件(.xml)中创建xml标记并查询数据库。我的xml标签采用以下格式:

<company comp:loc=" "/> 

现在我需要从SQL数据库中获取空白字段(loc =“”)的值。

如何从SQL数据库中获取java中xml标记的这些值?

1 个答案:

答案 0 :(得分:0)

        connection = dataSource.getConnection();
        ResultSet rs;
        connection.setAutoCommit(false);
        System.out.println("Connected to server OELDBSQL!!!");
        Statement stmt=connection.createStatement();
        String querystring="select loc from location";
        rs = stmt.executeQuery(querystring );
        while(rs.next())  {
        Element child1 = doc.createElement("company");
        child1.setAttributeNS(comp,"comp:loc", rs.getString (1));