| java.lang.Object org.isqlviewer.sql.JdbcUtilities
JdbcUtilities | final public class JdbcUtilities (Code) | | Utility class for dealing with JDBC oriented tasks.
None of the methods that deal with ResultSets will actually close the ResultSet when completed, a call to the method
first is called before and after each method is finished executing the defined function.
A small note about methods that use a the ResultSetViewer object as a parameter to the method is that if the
ResultSetViewer is null and an SQLException occurs an attempt will be made to add the respecting exception as a
warning to the given ResultSet object. So it recommended that if you want to know if an SQLException occured without
using the ResultSetViewer check for warnings on the ResultSet after method invocation.
author: Markus A. Kobold <mkobold at sprintpcs dot com> |
Method Summary | |
public static void | configurePreparedStatement(PreparedStatement ps, Object[] data, int[] type, boolean convert) Helper method to the other configurePreparedStatement method. | public static void | configurePreparedStatement(PreparedStatement ps, int index, Object value, int type, boolean convert) Helper method set data parameters of a PreparedStatement.
This method does make the assumption that the given object is of the correct type as this method will simply cast
the object to the appropriate class based on the given SQL-Type. | public static Object | convertValue(Object data, int type, Format fmt) Attempts to convert Object to it's standard type.
This method does make a fair attempt at conversion however it obviously can't convert everything. | public static synchronized Map<String, Object> | extractMetadata(DatabaseMetaData dmd) | public static String | generatePreparedInsertRequest(String Table, String[] Columns) Helper method to assist with creating insert commands for prepared statements.
This will create an SQL statement in the following format. | public static String | generatePreparedUpdateRequest(String Table, String[] Columns, String whereClause) Helper method to assist with creating update commands for prepared statements.
This will create an SQL statement in the following format. | public static HashMap<String, Integer> | getNativeTypeMap(DatabaseMetaData metaData) | public static String[] | getSQLTypes(boolean sorted) Returns a list of Strings of valid Java SQL types.
This method reflects through {
java.sql.Types } object to get the names of all the fields in that object and returns them as an array. Parameters: sorted - determines to sort the list or not. | public static int | getTypeforName(String name) Refelcts to get SQL Type constant by name. | public static String | getTypeforValue(int type) Reverse lookup of a type name based on the constant.
This will iterate through the declared fields of the Types.class and once the correct field int value match the
given type it will return the name of the field.
See Also: JdbcUtilities.getTypeforName(String) See Also: Types Parameters: type - to get Field name for. | public static Object | getValueForType(ResultSet set, int type, int idx) | public static boolean | isBooleanType(int type) Helper method for determining if a given type is one of the Boolean SQL types. | public static boolean | isDateType(int type) Helper method for determining if a given type is one of the date SQL types. | public static boolean | isNumberType(int type) Helper method for determining if a given type is one of the numerical SQL types. | public static boolean | isStringType(int type) Helper method for determining if a given type is one of the String SQL types. | public static boolean | isUpdatable(ResultSet rs) Checks if the ResultSet is deemed updatable.
Basically if the ResultSet has the UPDATABLE concurrency and is not of the FORWARD_ONLY type this method will
return true, IF the driver decides to throw exception when attempting to query this information this method will
always return false.
See Also: ResultSet.getConcurrency See Also: ResultSet.getType Parameters: rs - to check for updatability. |
configurePreparedStatement | public static void configurePreparedStatement(PreparedStatement ps, int index, Object value, int type, boolean convert) throws SQLException(Code) | | Helper method set data parameters of a PreparedStatement.
This method does make the assumption that the given object is of the correct type as this method will simply cast
the object to the appropriate class based on the given SQL-Type. The logic as to what type should be what object
is detailed in the convert method, as it is recommend to call convert before this method as the successful
execution of convert will most likely ensure success of this method.
If the given value is null setNull(int,int) will be called on the statement and return immediately.
See Also: JdbcUtilities.convertValue(Object,int,Format) Parameters: index - of the given parameter in the statement (index >= 1) Parameters: ps - PreparedStatement to configure. Parameters: type - for the given data object. throws: SQLException - if error occurs setting data. |
convertValue | public static Object convertValue(Object data, int type, Format fmt) throws ParseException, IOException(Code) | | Attempts to convert Object to it's standard type.
This method does make a fair attempt at conversion however it obviously can't convert everything. This method is
mainly to address working with the configurePreparedStatements as those method make the assumptions that the
objects are of type and simply casts them when appropriate.
Here is a rundown of what SQL Types goto what types. If the type is not listed here then object passed in will be
passed back.
Types :
Anything not on the above list will not be converted to anything.
See Also: Types See Also: JdbcUtilities.configurePreparedStatement(PreparedStatement,int,Object,int,boolean) Parameters: data - to convert Parameters: type - SQL type to convert to. Parameters: fmt - object to use if parsing the data is required. converted object. throws: ParseException - if using the format object parsing exception occurs. |
generatePreparedInsertRequest | public static String generatePreparedInsertRequest(String Table, String[] Columns)(Code) | | Helper method to assist with creating insert commands for prepared statements.
This will create an SQL statement in the following format.
INSERT INTO {Table} ({Colums[0],},.., {Columns[n]}) VALUES(?,..,?)
This method will return null if an exception occurs.
Parameters: Table - Name of table you wish to insert into. Parameters: Columns - List of column names to declare values for. Generated SQL statement for use with creating prepared statements. |
generatePreparedUpdateRequest | public static String generatePreparedUpdateRequest(String Table, String[] Columns, String whereClause)(Code) | | Helper method to assist with creating update commands for prepared statements.
This will create an SQL statement in the following format.
UPDATE {Table} SET {Colums[0]=?,},.., {Columns[n]=?} WHERE {whereClause}
This method will return null if an exception occurs.
Parameters: Table - Name of table you wish to update. Parameters: Columns - List of column names to update. Parameters: whereClause - Standard SQL where clause for this update. Generated SQL statement for use with creating prepared statements. |
getSQLTypes | public static String[] getSQLTypes(boolean sorted)(Code) | | Returns a list of Strings of valid Java SQL types.
This method reflects through {
java.sql.Types } object to get the names of all the fields in that object and returns them as an array. Parameters: sorted - determines to sort the list or not. String[] list of Types fields by name. |
getTypeforName | public static int getTypeforName(String name)(Code) | | Refelcts to get SQL Type constant by name.
Simple reflection utility to get the proper constant for the Type name.
See Also: Types See Also: JdbcUtilities.getTypeforValue(int) Parameters: name - valid field name in Types int representing the proper constant. |
getTypeforValue | public static String getTypeforValue(int type)(Code) | | Reverse lookup of a type name based on the constant.
This will iterate through the declared fields of the Types.class and once the correct field int value match the
given type it will return the name of the field.
See Also: JdbcUtilities.getTypeforName(String) See Also: Types Parameters: type - to get Field name for. name of the field of Types.class based on the given constant. |
isBooleanType | public static boolean isBooleanType(int type)(Code) | | Helper method for determining if a given type is one of the Boolean SQL types.
If the type equals BIT, BOOLEAN then this will return true otherwise false.
See Also: Types Parameters: type - SQL-Type to check true if the given type represents boolean objects |
isDateType | public static boolean isDateType(int type)(Code) | | Helper method for determining if a given type is one of the date SQL types.
If the type equals DATE,TIME,TIMESTAMP then this will return true otherwise false.
See Also: Types Parameters: type - SQL-Type to check true if the given type represents Date objects |
isNumberType | public static boolean isNumberType(int type)(Code) | | Helper method for determining if a given type is one of the numerical SQL types.
If the type equals BIGINT,DECIMAL,DOUBLE,FLOAT,INTEGER,NUMERIC,REAL,SMALLINT, and TINYINT then this will return
true otherwise false.
See Also: Types Parameters: type - SQL-Type to check true if the given type represents numerical objects |
isStringType | public static boolean isStringType(int type)(Code) | | Helper method for determining if a given type is one of the String SQL types.
If the type equals CHAR,VARCHAR,LONGVARCHAR then this will return true otherwise false.
See Also: Types Parameters: type - SQL-Type to check true if the given type represents String objects |
isUpdatable | public static boolean isUpdatable(ResultSet rs)(Code) | | Checks if the ResultSet is deemed updatable.
Basically if the ResultSet has the UPDATABLE concurrency and is not of the FORWARD_ONLY type this method will
return true, IF the driver decides to throw exception when attempting to query this information this method will
always return false.
See Also: ResultSet.getConcurrency See Also: ResultSet.getType Parameters: rs - to check for updatability. true if the ResultSet should support updates. |
|
|