CuriousMind
CuriousMind

Reputation: 8903

What data types to store db2 xml in java?

I have a requirement to get XML data stored in db2. In db2 the XML data is stored in a table column whose type is XML (db2).

Now if i have to retrieve it using plain JDBC (no other choice i have here), what is the java data type in which this should be mapped.

From what i researched, i feel it should be this way.

String xmlData = (String) resultSet.getObject(1); 

(assuming 1 is the column index where the xml data is stored)

Is this a viable solution? Any suggestions?

Upvotes: 0

Views: 1077

Answers (1)

wero
wero

Reputation: 32990

ResultSet has getSQLXML(int) which returns a java.sql.SQLXML object.
SQLXML gives you the most options to access the XML data.

Anyway you have a wide variety of options to retrieve the XML. According this doc you can simply use ResultSet.getString(int) if you want the data as String.

But as always it depends on the version of your DB2 and your JDBC driver if all these options are supported.

Upvotes: 1

Related Questions