日期:2014-05-16 浏览次数:21036 次
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;
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;
}
}
SELECT * FROM tab;