Here you can find the source of hasTable(Connection conn, String schemaName, String tableName)
public static boolean hasTable(Connection conn, String schemaName, String tableName)
//package com.java2s; /*/* w ww . j a v a 2 s.c o m*/ * Copyright 2015, Yahoo Inc. * Copyrights licensed under the Apache License. * See the accompanying LICENSE file for terms. */ import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; public class Main { public static boolean hasTable(Connection conn, String schemaName, String tableName) { ResultSet rs = null; try { rs = conn.getMetaData().getTables(null, schemaName, tableName.toUpperCase(), null); while (rs.next()) { if (tableName.equalsIgnoreCase(rs.getString("TABLE_NAME"))) return true; } } catch (Exception ex) { } finally { if (rs != null) try { rs.close(); rs = null; } catch (Exception iex) { } } return false; } public static void close(Statement stmt) { if (stmt != null) try { stmt.close(); } catch (Exception ex) { } } public static void close(ResultSet rs) { if (rs != null) try { rs.close(); } catch (Exception ex) { } } public static void close(Connection conn) { if (conn != null) try { conn.close(); } catch (Exception ex) { } } }