试试ResultSet rs = connect.getMetaData().getTables(null, null, "表名", null);看看rs中有没有你想要的表,详见DatabaseMetaData类的getTables方法。

解决方案 »

  1.   

    有个很笨的方法
    try
    {
    Statement stmt = connect.createStatement();
    stmt.executeQuery("select count(*) from yourTable");}
    catch(SQLException e)
    {
       System.out.print("不存在!"+ e.getMessage());
    }
      

  2.   

    jimjxr(宝宝猫)
    请问,为什么存在和不存在的表显示的是同样的信息呢?
    我哪些信息上可以判断这个表是否存在呢?
      

  3.   

    同意 yanchang(笨笨)的方法,呵呵
      

  4.   

    应该可以依赖于数据库来实现吧,比如oracle: select * from tabs where table_name = 'ur table name';对于slect count(*) from 'ur table name' 然后catch exception的方法应该慎用,count(*)对大表会影响性能的。
      

  5.   

    获得表中的信息
    你可对DataBaseMetaData对象使用getTables()方法以得到数据库中表的信息。这
    个方法有以下四个字符串参数: results = dma.getTables(catalog, schema, tablemask, types[]);参数的意义为: catalog
     用来寻找表名的目录名称。对于JDBC-ODBC数据
    库和许多其它的数据库,它可被设置为null。这些数
    据库的目录条目实际上为它们在文件系统中的绝对
    路径。 
    schema
     要包括的数据库schema。许多数据库并不支持
    schema,而对于其它的数据库,它为数据库所有者
    的用户名称。 
    tablemask
     描述你要获取的表的名称的一个掩码。若你想获取
    所有的表名,将它设为通配符%。注意SQL用%作
    为通配符,而不是PC上的*。 
    types[]
     描述你奥获取的表的种类的一个字符串数组。数据
    库中通常包括一些用于内部管理的表,而这些表对
    用户来说是毫无用处的。若被设为null,你将得到所
    有的表。若使该数组只包括一个元素,且将该元素
    设为字符串“TABLES”,你将得到用户所感兴趣
    的那些表。 获得数据库中表的名称相对于先得到DatabaseMetaData对象,然后再从中取得表的名称。 con = DriverManager.getConnection(url);
    //get the database metadata
    dma =con.getMetaData();
    //now dump out the names of the tables in the database
    String[] types = new String[1];
    types[0] = "TABLES"; //set table type mask
    //note the %-sign is a wild card (not '*')
    results = dma.getTables(null, null, "yourtablename", types);如我们在前面所做的,打印出表的名称: boolean more = results.next();
    if (more) 
    {
    //yourtablename已经存在!
    }将所有代码包括在try程序块中。 
    但我建议还是用yanchang(笨笨) ,比较方便