From 7cb5081692caf0d5eecbcb4dd71588c4f8a2338a Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 27 May 2004 02:04:34 +0000 Subject: [PATCH] Add the metadata acquisition of index info. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1438 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/jdbc/JDBCUtil.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java b/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java index 42d3f52e..cf3fd129 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.8 2004/05/17 15:58:45 mdb Exp $ +// $Id: JDBCUtil.java,v 1.9 2004/05/27 02:04:34 eric Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -183,6 +183,29 @@ public class JDBCUtil return matched; } + + /** + * Returns true if the index on the specified column exists for the + * specified table. false if it does not. Note: the names are + * case sensitive. + */ + public static boolean tableContainsIndex (Connection conn, String table, + String column) + throws SQLException + { + boolean matched = false; + ResultSet rs = conn.getMetaData().getIndexInfo("", "", table, false, + true); + 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; + } + /** * Returns true if the table with the specified name exists and * contains a column with the specified name, false if either