日期:2014-05-16  浏览次数:20750 次

java 调用oracle存储过程建表出错,求解
oracle建的创建建表的存储过程其中有外键约束, 在sqlplusw中调用没有问题,外键约束可以建出来,但是在java中调用创建的表就没有外键约束 ,报的错误:
ORA-00955: 名称已由现有对象使用
ORA-06512: 在 "SCOTT.BUILDDATA", line 19
ORA-06512: 在 line 1
数据库中没有这两个表,已经删掉后的。
先贴过程
CREATE OR REPLACE 
procedure builddata1 is

v_comsql VARCHAR2(2000);
v_myusersql VARCHAR2(2000);
v_comcount number(30);
v_usercount number(30);

begin
v_comsql:='
create table com(
com_name varchar2(20) not null unique,
com_order varchar2(20) primary key ,
bcom_order varchar2(20) not null unique,
com_ispare char(2) not null)';
v_myusersql:='create table myuser(
user_id char(32) primary key,
user_name varchar2(20) not null unique,
user_password varchar2(20) not null,
user_ispare char(2) not null,
branch_order varchar2(20) REFERENCES com(com_order)
)';

select count(*) into v_comcount from user_tables where table_name='COM';
if v_comcount=0 then
  execute immediate v_comsql;
else
  dbms_output.put_line('com表存在');
end if;

select count(*) into v_usercount from user_tables where table_name='MYUSER';

if v_usercount=0 then
  execute immediate v_myusersql;
else
  dbms_output.put_line('myuser表存在');
end if;

exception
when others then
dbms_output.put_line('创建表异常');
end builddata1;



再贴java代码:

package com.manage.session;

import org.hibernate.Query;
import org.hibernate.Session;


public class InstallDb {
private Session session;

public boolean installDb(){

boolean i=false;
try{
session=HibernateSessionFactory.getSession();
session.beginTransaction();

Query query=session.createSQLQuery("{call builddata()}");
query.executeUpdate(); 
session.getTransaction().commit();
i=true;

}catch(Exception e){
session.getTransaction().rollback();
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return i;
}

}