|
© 2005 BEA Systems, Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bea.p13n.content.document.ref.loader.ColumnSizes
Utility class to help determine JDBC table column sizes and to truncate data for inserting.
The general usage of this class should be truncate data fields before
sending them to the database to avoid extraneous errors when data
truncation would be a valid solution. For example,
String id = request.getParameter("id");
String name = request.getParameter("name");
String value = request.getParameter("value");
Connection con =
DriverManager.getConnection("jdbc:weblogic:jts:commercePool");
String sql = "INSERT INTO MYTABLE (ID, NAME, VALUE) VALUES (?, ?, ?)";
PreparedStatement stmt = con.prepareStatment(sql);
id =
ColumnSizes.truncate
(id, con, "MYTABLE", "ID");
stmt.setString(1, id);
name = ColumnSizes.truncate
(name, con, "MYTABLE", "NAME");
stmt.setString(2, name);
value = ColumnSizes.truncate
(value, con, "MYTABLE", "VALUE");
stmt.setString(3, value);
stmt.executeUpdate();
stmt.close();
con.close();
Additionally, you can use the getColumnInfo()
method to determine the size of a table column. In this manner, you could
warn the user about the max size or about data truncation.
When determining the size of columns, the following logic is used:
Note: Setting p13n.jdbc.maxsize.checkMetaData to true will cause the java.sql.DatabaseMetaData.getColumns() method to be invoked. Some JDBC drivers do not support this method correctly. Some Type 2 drivers might core dump on this method call.
Nested Class Summary | |
static class |
ColumnSizes.ColumnInfo
Deprecated. Object describing a column. |
Field Summary | |
static int |
BOOLEAN
Deprecated. The constant for a boolean type (0). |
static boolean |
CHECK_META_DATA
Deprecated. Should we check with the DatabaseMetaData for getting column sizes. |
static int |
DATETIME
Deprecated. The constant for a datetime type (4). |
static int |
FLOAT
Deprecated. The constant for the floating-point numeric type (2). |
static int |
INTEGER
Deprecated. The constant for a numeric type (1). |
static int |
MULTI_VALUED
Deprecated. The constant for a multivalued type (6). |
static int |
TEXT
Deprecated. The constant for a text type (3). |
static int |
USER_DEFINED
Deprecated. The constant for a user defined type (5). |
Constructor Summary | |
ColumnSizes()
Deprecated. |
Method Summary | |
static int |
fromSQLType(int sqlType)
Deprecated. Convert a java.sql.Types constant into one of ours. |
static ColumnSizes.ColumnInfo |
getColumnInfo(Connection con,
String table,
String column)
Deprecated. Get the ColumnInfo for the specified column. |
static String |
getTypeName(int type)
Deprecated. Get the default descriptive type name. |
static Object |
truncate(Object in,
Connection con,
String table,
String column)
Deprecated. Truncate the specified object to the size of the specified table/column. |
static String |
truncate(String in,
Connection con,
String table,
String column)
Deprecated. Truncate the specified String to the size of the specified table/column. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int BOOLEAN
public static boolean CHECK_META_DATA
This is initialized from the "p13n.jdbc.maxsize.checkMetaData" property in the weblogiccommerce.properties.
public static final int DATETIME
public static final int FLOAT
public static final int INTEGER
public static final int MULTI_VALUED
public static final int TEXT
public static final int USER_DEFINED
Constructor Detail |
public ColumnSizes()
Method Detail |
public static int fromSQLType(int sqlType)
sqlType
- value from java.sql.Types.
public static ColumnSizes.ColumnInfo getColumnInfo(Connection con, String table, String column) throws SQLException
If the column information is not found in the cache, it will be loaded (see class comments for details on how it is loaded).
con
- the connection to use, null to not.table
- the table name.column
- the column name.
SQLException
- if the information cannot be loaded.public static String getTypeName(int type)
public static Object truncate(Object in, Connection con, String table, String column)
public static String truncate(String in, Connection con, String table, String column)
truncate(java.lang.Object, java.sql.Connection, java.lang.String, java.lang.String)
|
© 2005 BEA Systems, Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |