Would you please tell me how to insert big XML into DB2 9?
I'm using DB2 v9.1 Express-C.
Thanks in advance!
Mike
Mar. 26, 2007
> Hi all,
> I encountered a problem while INSERTing a 160KB well formed XML
> document into the XML field. I heard that DB2 9 can store up to 2G
> bytes XML document, but my insertion was failed with just 160KB XML.
> DB2 complains that the "string constant is too long" (SQLSTATE 54002).
> I inserted the data via SQL command.
>
> Would you please tell me how to insert big XML into DB2 9?
What's the exact INSERT statement and what's the exact error message that
you got?
Also, what's your environment (OS, DB2 release level)?
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
I use DB2 9 Express-C on Windows 2003 Server. The table "talk" was
create by:
CREATE TABLE talk (tid BIGING, content XML) IN reldata LONG IN xmldata
And reldata is a tablespace with 4k pagesize, xmldata is a tablespace
with 32k pagesize.
The inserting command is issued by a C# program with DB2Command
object. Here is the code snippet:
DB2Command cmd = connection.CreateCommand();
cmd.CommandText = "INSERT INTO talk (tid, content) VALUES (4,
XMLPARSE(DOCUMENT'" + sb.ToString() + "'))";
The sb object is a .NET StringBuilder object, in which stored a 160KB
XML document.
The error message is:
ERROR [54002] [IBM][DB2/NT] SQL0102N The string constant beginning
with "blah blah" is too long。SQLSTATE=54002
Thanks again.
DB2Command cmd = connection.CreateCommand();
cmd.CommandText "INSERT INTO talk (tid, content) VALUES (5, @xmldoc)";
cmd.Parameters.Add("@xmldoc", sb.ToString());
This time it did not complain SQLSTATE 54002, instead, it says:
ERROR [22001] [IBM] CLI0109E String data right truncation.
SQLSTATE=22001
How can I do?
Thanks!
On 3月27日, 上午3时07分, Knut Stolze <sto...@de.ibm.com> wrote:
Hi all,
Try to use:
String query = "INTO talk (tid, content) VALUES (?, ?)";
PreparedStatement insertStmt = conn.prepareStatement(query);
insertStmt.setInt(1, 4);
insertStmt.setString(2, sb.ToString());
insertStmt.executeUpdate();
What is else I recommend for all DB2 9 pureXML Guidebook. You can
download it free from http://www.redbooks.ibm.com/abstracts/SG247315.html
Marcin Molak
Warsaw University of Technology, Faculty of Physics student
Mike
March. 27
> Try to use:
>
> String query = "INTO talk (tid, content) VALUES (?, ?)";
> PreparedStatement insertStmt = conn.prepareStatement(query);
> insertStmt.setInt(1, 4);
> insertStmt.setString(2, sb.ToString());
> insertStmt.executeUpdate();
>
> What is else I recommend for all DB2 9 pureXML Guidebook. You can
> download it free fromhttp://www.redbooks.ibm.com/abstracts/SG247315.html
> Hi Knut,
> I tried again with host variable. That is,
>
> DB2Command cmd = connection.CreateCommand();
> cmd.CommandText "INSERT INTO talk (tid, content) VALUES (5, @xmldoc)";
> cmd.Parameters.Add("@xmldoc", sb.ToString());
>
> This time it did not complain SQLSTATE 54002, instead, it says:
>
> ERROR [22001] [IBM] CLI0109E String data right truncation.
> SQLSTATE=22001
>
> How can I do?
I checked with the manuals, and the serialized (string) representation of
XML documents is limited to 2GB.
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.apdv.embed.doc/doc/c0023366.htm
So that shouldn't be an issue in your case. My guess is that you exceed the
total SQL statement length - not knowing what exactly "cmd.Parameters.Add"
is doing.
> Thank you very much. The problem has been solved.
How did you resolve it?