3

Oracle 11g R2 を使用しています。いくつかのユーザー テーブルを作成したいと考えています。クエリを実行すると。いくつかのテーブルが作成され、java.sql.SQLSyntaxErrorException: ORA-00955: name is already used by an existing object Exception が生成されます。

    Connection con=prepareConnection();
    Statement st=con.createStatement();
    StringBuilder sb=new StringBuilder(1024);
    sb.append("create table ").append(uname).append("(MESSAGES CLOB,LINKS VARCHAR2(150),FRIENDS VARCHAR2(50),COMMENTS CLOB,LIKES VARCHAR2(10),UNLIKES VARCHAR2(10),SHARES BLOB,QSTNS CLOB,ANS CLOB,UPDATES BLOB,THEMS VARCHAR2(100),WORDS CLOB,NOTIFICATION CLOB,REQUESTS VARCHAR2(100),TIPS CLOB,TAG VARCHAR2(50))");
    String Query=sb.toString();
    st.executeUpdate(Query);

    Statement st1=con.createStatement();
    StringBuilder sb1=new StringBuilder(1024);
    sb1.append("create table ").append(uname).append("VIALBUM(ALBUMID NUMBER NOT NULL, ALBUMNAME VARCHAR2(225) NOT NULL, CONSTRAINT ").append(uname).append("VIALBUM_PK PRIMARY KEY(ALBUMID)ENABLE)");
    String Query1=sb1.toString();
    st1.executeUpdate(Query1);

    Statement st12=con.createStatement();
    StringBuilder sb12=new StringBuilder(1024);
    sb12.append("CREATE INDEX ").append(uname).append("VIALBUM_INDEX ON ").append(uname).append("VIALBUM(ALBUMNAME)");
    String Query12=sb12.toString();
    st12.executeUpdate(Query12);

    Statement st11=con.createStatement();
    StringBuilder sb11=new StringBuilder(1024);
    sb11.append("create table ").append(uname).append("VIDEO(VIDEOID NUMBER NOT NULL, VIDEONAME VARCHAR2(225) NOT NULL, VIDEOFULL BLOB NOT NULL, VIDEODISC VARCHAR2(225), ALBUMID NUMBER NOT NULL, CONSTRAINT ").append(uname).append("VIDEO_PK PRIMARY KEY(VIDEOID)ENABLE)");
    String Query11=sb11.toString();
    st11.executeUpdate(Query11);

    Statement st13=con.createStatement();
    StringBuilder sb13=new StringBuilder(1024);
    sb13.append("ALTER TABLE ").append(uname).append("VIDEO ADD CONSTRAINT ").append(uname).append("VIDEO_").append(uname).append("VIALBUM_FK1 FOREIGN KEY(ALBUMID)REFERENCES ").append(uname).append("VIALBUM(ALBUMID)ENABLE");
    String Query13=sb13.toString();
    st13.executeUpdate(Query13);

    Statement st14=con.createStatement();
    StringBuilder sb14=new StringBuilder(1024);
    sb14.append("CREATE INDEX ").append(uname).append("VIDEO_INDEX ON ").append(uname).append("VIDEO (VIDEONAME)");
    String Query14=sb14.toString();
    st14.executeUpdate(Query14);

    Statement st2=con.createStatement();
    StringBuilder sb2=new StringBuilder(1024);
    sb2.append("create table ").append(uname).append("ALBUM(ALBUMID NUMBER NOT NULL, ALBUMNAME VARCHAR2(225) NOT NULL, CONSTRAINT ").append(uname).append("ALBUM_PK PRIMARY KEY(ALBUMID)ENABLE)");
    String Query2=sb2.toString();
    st2.executeUpdate(Query2);

    Statement st22=con.createStatement();
    StringBuilder sb22=new StringBuilder(1024);
    sb22.append("CREATE INDEX ").append(uname).append("ALBUM_INDEX ON ").append(uname).append("ALBUM(ALBUMNAME)");
    String Query22=sb22.toString();
    st22.executeUpdate(Query22);

上記のステートメントまで、正しく実行されます。残りのステートメントは実行されず、例外がスローされます。

    Statement st21=con.createStatement();
    StringBuilder sb21=new StringBuilder(1024);
    sb21.append("create table ").append(uname).append("IMAGE(IMAGEID NUMBER NOT NULL, IMAGENAME VARCHAR2(225) NOT NULL, IMAGEFULL BLOB NOT NULL, IMAGEDISC VARCHAR2(225), ALBUMID NUMBER NOT NULL, CONSTRAINT ").append(uname).append("IMAGE_PK PRIMARY KEY(IMAGEID)ENABLE)");
    String Query21=sb11.toString();
    st21.executeUpdate(Query21);

    Statement st23=con.createStatement();
    StringBuilder sb23=new StringBuilder(1024);
    sb23.append("ALTER TABLE ").append(uname).append("IMAGE ADD CONSTRAINT ").append(uname).append("IMAGE_").append(uname).append("ALBUM_FK1 FOREIGN KEY(ALBUMID)REFERENCES ").append(uname).append("ALBUM(ALBUMID)ENABLE");
    String Query23=sb23.toString();
    st23.executeUpdate(Query23);

    Statement st24=con.createStatement();
    StringBuilder sb24=new StringBuilder(1024);
    sb24.append("CREATE INDEX ").append(uname).append("IMAGE_INDEX ON ").append(uname).append("IMAGE (IMAGENAME)");
    String Query24=sb24.toString();
    st24.executeUpdate(Query24);

    Statement st3=con.createStatement();
    StringBuilder sb3=new StringBuilder(1024);
    sb3.append("create table ").append(uname).append("MUALBUM(ALBUMID NUMBER NOT NULL, ALBUMNAME VARCHAR2(225) NOT NULL, CONSTRAINT ").append(uname).append("MUALBUM_PK PRIMARY KEY(ALBUMID)ENABLE)");
    String Query3=sb3.toString();
    st3.executeUpdate(Query3);

    Statement st32=con.createStatement();
    StringBuilder sb32=new StringBuilder(1024);
    sb32.append("CREATE INDEX ").append(uname).append("MUALBUM_INDEX ON ").append(uname).append("MUALBUM(ALBUMNAME)");
    String Query32=sb12.toString();
    st32.executeUpdate(Query32);

    Statement st31=con.createStatement();
    StringBuilder sb31=new StringBuilder(1024);
    sb31.append("create table ").append(uname).append("SONG(SONGID NUMBER NOT NULL, SONGNAME VARCHAR2(225) NOT NULL, SONGFULL BLOB NOT NULL, SONGDISC VARCHAR2(225), ALBUMID NUMBER NOT NULL, CONSTRAINT ").append(uname).append("SONG_PK PRIMARY KEY(SONGID)ENABLE)");
    String Query31=sb31.toString();
    st31.executeUpdate(Query31);

    Statement st33=con.createStatement();
    StringBuilder sb33=new StringBuilder(1024);
    sb33.append("ALTER TABLE ").append(uname).append("SONG ADD CONSTRAINT ").append(uname).append("SONG_").append(uname).append("ALBUM_FK1 FOREIGN KEY(ALBUMID)REFERENCES ").append(uname).append("ALBUM(ALBUMID)ENABLE");
    String Query33=sb33.toString();
    st33.executeUpdate(Query33);

    Statement st34=con.createStatement();
    StringBuilder sb34=new StringBuilder(1024);
    sb34.append("CREATE INDEX ").append(uname).append("SONG_INDEX ON ").append(uname).append("SONG (SONGNAME)");
    String Query34=sb34.toString();
    st34.executeUpdate(Query34);

このエラーの意味を教えてください。

4

2 に答える 2

2

このコードを実行するString Query21=sb11.toString();と、上記で作成済みのテーブルを作成しようとします。

たぶん、これで問題が解決String Query21=sb21.toString();する可能性があります

于 2013-01-30T11:37:42.580 に答える
1

テーブルや制約、フィールドなど、別のオブジェクトと同じ名前のオブジェクトを作成しようとしているようです。

ここで同じテーブルを 2 回作成しようとしたようです。

String Query21=sb11.toString();
于 2013-01-30T11:40:41.513 に答える