How can I insert an XML document in PostgreSQL in Java?

后端 未结 4 1151
不思量自难忘°
不思量自难忘° 2021-01-02 18:54

I have a table in Postgresql

DROP TABLE xml_docs;
CREATE TABLE xml_docs(
id serial PRIMARY KEY,
cad_number character(50),
gkuzu_name character(50),
gkuzu xm         


        
4条回答
  •  有刺的猬
    2021-01-02 19:17

    An update to the accepted answer if you do not have Postgres built with libxml support:

    Java code example:

    String sql = "INSERT INTO xml_docs(id, gkuzu) VALUES (?, XML(?))";
    [...]
    stmt.setString(2, "Hello World!");
    

    This should create this statement:

    INSERT INTO xml_docs(id, gkuzu) VALUES (1, XML('Hello World!'));
    

    Thus for version 9.0 and greater you may want to switch XMLPARSE ==> XML. Otherwise you will need special support for XMLPARSE

    From Postgres Documentation:

    The function-like expressions xmlparse and xmlserialize for converting to and from type xml are not repeated here. Use of most of these functions requires the installation to have been built with configure --with-libxml.

提交回复
热议问题