public boolean validateTableExist(String tableName){
int result = 0;
String sql = "SELECT COUNT(*) FROM USER_OBJECTS WHERE OBJECT_NAME = UPPER('"+tableName+"')";
Connection conn = this.getSession().connection();
Statement st = null;
ResultSet rs = null;
try{
st = conn.createStatement();
rs = st.executeQuery(sql);
rs.next();
result = rs.getInt(1);
}catch(Exception e){
e.printStackTrace();
}finally{
this.util.closeAll(rs, st, conn);
}
return result==0?false:true;
}
JDBC的完整方法,CloseAll方法就不给你写了.如果表存在就返回True,不存在返回False,可以直接用在你的IF判断中:
if(validateTableExist(tname)){
String sql1="insert into "+tname+" values(?,?,?,?,?,?)";
....................
}
可以用Oracle的辅助表 Select * from User_tables where table_name='xxxx' 如果返回结果为空, 说明表不存在
select 1 from user_tables where table_name='表名'
如果=1 表存在