From 49ff4d36a7b6eec7b8400fdc414d37cc543a21af Mon Sep 17 00:00:00 2001 From: andrzej Date: Mon, 20 Nov 2006 19:20:13 +0000 Subject: [PATCH] Added method to check if a column is nullable. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1976 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/jdbc/JDBCUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/java/com/samskivert/jdbc/JDBCUtil.java b/src/java/com/samskivert/jdbc/JDBCUtil.java index 3ec046a5..8bbb5007 100644 --- a/src/java/com/samskivert/jdbc/JDBCUtil.java +++ b/src/java/com/samskivert/jdbc/JDBCUtil.java @@ -429,6 +429,24 @@ public class JDBCUtil } } + /** + * Determines whether or not the specified column accepts null values. + * + * @return true if the column accepts null values, false if it does not + * (or its nullability is unknown) + */ + public static boolean isColumnNullable (Connection conn, String table, + String column) + throws SQLException + { + ResultSet rs = getColumnMetaData(conn, table, column); + try { + return rs.getString("IS_NULLABLE").equals("YES"); + } finally { + rs.close(); + } + } + /** * Returns the size for the specified column in the specified table. For * char or date types this is the maximum number of characters, for numeric