我也想过设置一个成功标志TABLEXIST,如果表存在,则TABLEXITST=1;不存在则TABLEXIST=0,但是好像JSP里面的变量不能和SQL的变量通用,比如我在JSP里定义TABLEXIST=0,就无法在SQL语句里对TABLEXIST进行操作stm3.executeQuery("if exists (select * from sysobjects where name ='"+T2001+"'"+ TABLEXIST+"='1'");

解决方案 »

  1.   

    查数据字典 dbo.sysobjectselect count(*) as n from sysobject where name=tablenamen 等于 1 时 tablename 存在,等于 0 时,tablename 不存在。
      

  2.   

    恩,多谢楼上的,我已经解决了,方法跟你说的差不多,
    //判断表是否存在
    int table = 0;
     ResultSet rt=stm3.executeQuery("select * from sysobjects where name ='"+T2001+"'");
       if(history_trace_rt.next())
        {
          table = 1;
        }
    如果TABLE=1,则进行以下的查询,否则就不操作。我最开始是被IF EXISTS给误导了,后来才想到直接使用select * from sysobjects where name ='T2001'也会返回一个结果集。