From 017dac2108c6e516ccbc2838d6b1e35fad26b6ba Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 25 Feb 2005 00:06:55 +0000 Subject: [PATCH] Added method that gets the type of column. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1598 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/jdbc/JDBCUtil.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java b/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java index fa462682..d3549a30 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/JDBCUtil.java @@ -288,6 +288,30 @@ public class JDBCUtil return null; } + /** + * Returns the type (as specified in {@link java.sql.Types} for the + * specified column in the specified table. + */ + public static int getColumnType (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"); + int type = rs.getInt("DATA_TYPE"); + if (tname.equals(table) && cname.equals(column)) { + return type; + } + } + + throw new SQLException("Table or Column not defined. [table=" + table + + ", col=" + column + "]."); + } + /** * Adds a column (with name 'cname' and definition 'cdef') to the * specified table.