Added method that gets the type of column.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1598 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
eric
2005-02-25 00:06:55 +00:00
parent 1f500e7272
commit 017dac2108
@@ -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.