- Added changeColumn, which allows you to change a column's definition.

Can be used to change the name of a column as well (I.e., the definition
  is the same except you give it a new name.)
--This   line, and those below, will be ignored--

M    src/java/com/samskivert/jdbc/JDBCUtil.java


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1591 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
eric
2005-02-17 19:44:45 +00:00
parent 14036f3060
commit 2d45af601f
@@ -323,6 +323,34 @@ public class JDBCUtil
"'.");
}
/**
* Changes a column's definition. Takes a full column definition
* 'cdef' (including the name of the column) with which to replace the
* specified column 'cname'.
*
* NOTE: A handy thing you can do with this is to rename a column by
* providing a column definition that has a different name, but the
* same column type.
*/
public static void changeColumn (Connection conn, String table,
String cname, String cdef)
throws SQLException
{
String update = "ALTER TABLE " + table + " CHANGE " + cname + " " +
cdef;
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement(update);
stmt.executeUpdate();
} finally {
close(stmt);
}
Log.info("Database column '" + cname + "' of table '" + table +
"' modified to have this def '" + cdef + "'.");
}
/**
* Removes a named index from the specified table.
*/