Java.sql.SQLSyntaxErrorException: ORA-00955: name is already in use by an existing object

I am using Oracle 11g R2, I want to create some custom tables. When I run the request. It creates multiple tables and throws java.sql.SQLSyntaxErrorException: ORA-00955: The name is already in use by an existing object .

    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);

      

Verbatim instructions are followed correctly. The rest of the operators are not executed. Throws an exception.

    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);

      

Please tell me what this error says.

+3


source to share


2 answers


It looks like you are trying to create some object with the same name as another. table or constraint, field, etc.

It looks like you tried to create the same table twice:



String Query21=sb11.toString();

      

+1


source


When you run this code String Query21=sb11.toString();

, you are trying to create a table that was already created above.



Maybe ths String Query21=sb21.toString();

can save you some trouble.

+2


source







All Articles