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

后端 未结 4 1175
不思量自难忘°
不思量自难忘° 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:03

    I'm not sure, but try this:

    First convert your XML to a Java String. Then create an insert statement und use the XMLPARSE method of PostgreSQL to convert your value to the xml type of PostgreSQL:

    INSERT INTO xml_docs(id, gkuzu) VALUES (1, XMLPARSE('Hello'));
    

    See: http://wiki.postgresql.org/wiki/XML_Support

    UPDATE:

    Java code example:

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

    This should create this statement:

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

提交回复
热议问题