Search code examples
oraclejdbcoracle10gora-00911

How to include multiple commands in a JDBC SQL query to Oracle 10g?


I'm completely new to Oracle (I come from MySQL and MSSQL) and am novice at JDBC. One of my table creation queries looks like this:

CREATE TABLE  "LISTS" 
   ("ID" NUMBER NOT NULL ENABLE, 
    "NAME" VARCHAR2(1000) NOT NULL ENABLE, 
    "DOMAIN_ID" NUMBER NOT NULL ENABLE, 
     CONSTRAINT "LISTS_PK" PRIMARY KEY ("ID") ENABLE
   )
/

CREATE OR REPLACE TRIGGER  "BI_LISTS" 
  before insert on "LISTS"               
  for each row  
begin   
    select "LISTS_SEQ".nextval into :NEW.ID from dual; 
end; 

/
ALTER TRIGGER  "BI_LISTS" ENABLE
/

When I try to connection.createStatement().execute() this query, I get java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option. If I remove the slashes, I get the same. If I try replacing them with semicolons, I get java.sql.SQLSyntaxErrorException: ORA-00911: invalid character.

Is it not possible to include multiple commands in one query in JDBC and/or Oracle? Or am I just missing some kind of syntax to separate them?


Solution

  • Each of those are separate statements. Issue one at a time via separate Statement objects via Connection#createStatement() or via multiple SQL calls to Statement#execute(String).

    Conversely, what is your reason for wanting them in one delineated statement?