Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004

    Unanswered: howto insert xml using jdbc


    I've been attempting to insert an xml document from a java program, and can't figure out what I'm doing wrong.

    My code is as follows:
    //try block to execute UPDATE statement to update the customer name from American Motors to IBM
    cmd = "insert into xmldata (uid, application, xmldata) values (?, ?, DB2XML.XMLVarchar(cast (? as varchar(1000))))";
    System.out.println("Inserting an XML document");

    PreparedStatement ps = dbConn2.prepareStatement(cmd);
    ps.setInt(1, 197878);
    ps.setString(2, "stratics");
    ps.setString(3, JoxTest.getUserSessionXML());

    boolean update = ps.execute(cmd);
    cmd = "select xmldata from xmldata where uid = 197878";
    System.out.println("Selecting inserted UserSession");

    ResultSet r1 = s1.executeQuery(cmd);

    while (
    String xmldoc = r1.getString(1);
    System.out.println("Inserted xmldoc: " + xmldoc);
    catch (Exception e)

    The error message is: [IBM][CLI Driver] CLI0100E Wrong number of parameters. SQLSTATE=07001

    So I immediately checked the number of columns in the table, and number of parameters supplied.. all equal 3.

    The table create is:
    create table xmldata (uid integer not null PRIMARY KEY, application varchar(35) not null, xmldata db2xml.XMLVarchar)

    the JoxTest.getUserSessionXML() returns a String. I have double checked this string, and it is a valid XML document.



  2. #2
    Join Date
    Feb 2004

    Re: howto insert xml using jdbc

    figured it out...

    just removed the cmd from the execute line.

    boolean update = ps.execute(); NOT boolean update = ps.execute(cmd);

    ah... sometimes its the simple things isn't it.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts