Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2012

    Question Unanswered: java problem with semicolon as statement separator

    I am connection to DB2 Express-C v10.1 for windows from my java program and trying to execute two queries in a single statement. I am using db2jcc.jar to establish my JDBC connection.

    I am getting DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, bla bla bla bla ;BEGIN-OF-STATEMENT;<space>, DRIVER=3.63.123

    If I break the two query and execute them separately it just works as expected. How can I resolve this.

    ALTER TABLE "table name" ADD CONSTRAINT "xxx" PRIMARY KEY ("xxxxx", "xxxxx", "xxxxx", "xxxxx");CREATE UNIQUE INDEX "xxxxx" ON "xxxxx" ("xxxxx", "xxxxx", "xxxxx", "xxxxx")

  2. #2
    Join Date
    Jan 2003
    Provided Answers: 5
    You cannot. They have to be separate statements executed separately.


  3. #3
    Join Date
    Mar 2003
    What makes you think that this is at all possible? First, you must create the index before the primary key (otherwise db2 will atomatically create an index to support the p.k.). Second, I dont know what method you used to execute the stmt, but I'm pretty sure it is supposed to execute exactly 1stmt. The only way I can think of is to add the two stmts to an anonoumus block, and then execute that, but I have no idea whether that will work via jdbc.

  4. #4
    Join Date
    Jun 2003
    Toronto, Canada
    Provided Answers: 1
    You can use a compound statement, something like this (not tested):
    stmt.execute("begin atomic " +
      "insert into blah; " +
      "update blah; " +
    However, I'm not sure you will be able to execute DDL statements like that. You may need to use a compiled compound SQL and EXECUTE IMMEDIATE:
    stmt.execute("begin  " +
      "execute immediate 'alter table blah'; " +
    + "end");
    "It does not work" is not a valid problem statement.

Tags for this Thread

Posting Permissions

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