diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java b/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java index d42cfdfb..42d3f52e 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java @@ -1,5 +1,5 @@ // -// $Id: JDBCUtil.java,v 1.7 2004/04/30 02:38:10 mdb Exp $ +// $Id: JDBCUtil.java,v 1.8 2004/05/17 15:58:45 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -164,4 +164,44 @@ public class JDBCUtil return text; } } + + /** + * Returns true if the table with the specified name exists, false if + * it does not. Note: the table name is case sensitive. + */ + public static boolean tableExists (Connection conn, String name) + throws SQLException + { + boolean matched = false; + ResultSet rs = conn.getMetaData().getTables("", "", name, null); + while (rs.next()) { + String tname = rs.getString("TABLE_NAME"); + if (name.equals(tname)) { + matched = true; + } + } + return matched; + } + + /** + * Returns true if the table with the specified name exists and + * contains a column with the specified name, false if either + * condition does not hold true. Note: the names are case + * sensitive. + */ + public static boolean tableContainsColumn ( + Connection conn, String table, String column) + throws SQLException + { + boolean matched = false; + ResultSet rs = conn.getMetaData().getColumns("", "", table, column); + while (rs.next()) { + String tname = rs.getString("TABLE_NAME"); + String cname = rs.getString("COLUMN_NAME"); + if (tname.equals(table) && cname.equals(column)) { + matched = true; + } + } + return matched; + } }