|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.springframework.jdbc.support.JdbcUtils
Generic utility methods for working with JDBC.
| Constructor Summary | |
JdbcUtils()
|
|
| Method Summary | |
static void |
closeResultSet(java.sql.ResultSet rs)
Close the given JDBC ResultSet and ignore any thrown exception. |
static void |
closeStatement(java.sql.Statement stmt)
Close the given JDBC Statement and ignore any thrown exception. |
static int |
countParameterPlaceholders(java.lang.String str,
char placeholder,
char delim)
Count the occurrences of the character placeholder in an SQL string
str. |
static int |
countParameterPlaceholders(java.lang.String str,
char placeholder,
java.lang.String delimiters)
Count the occurrences of the character placeholder in an SQL string
str. |
static java.lang.Object |
extractDatabaseMetaData(javax.sql.DataSource dataSource,
DatabaseMetaDataCallback action)
Extract database meta data. |
static boolean |
isNumeric(int sqlType)
Check that a SQL type is numeric. |
static int |
translateType(int sqlType)
Translate a SQL type into one of a few values: All integer types are translated to Integer. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public JdbcUtils()
| Method Detail |
public static void closeStatement(java.sql.Statement stmt)
stmt - the JDBC Statement to closepublic static void closeResultSet(java.sql.ResultSet rs)
rs - the JDBC ResultSet to close
public static java.lang.Object extractDatabaseMetaData(javax.sql.DataSource dataSource,
DatabaseMetaDataCallback action)
throws MetaDataAccessException
This method will open a connection to the database and retrieve the database metadata. Since this method is called before the exception translation feature is configured for a datasource, this method can not rely on the SQLException translation functionality.
Any exceptions will be wrapped in a MetaDataAccessException. This is a checked exception and any calling code should catch and handle this exception. You can just log the error and hope for the best, but there is probably a more serious error that will reappear when you try to access the database again.
dataSource - the DataSource to useaction - callback that will do the actual work
MetaDataAccessException
public static int countParameterPlaceholders(java.lang.String str,
char placeholder,
char delim)
placeholder in an SQL string
str. The character placeholder is not counted if it
appears within a literal as determined by the delim that is passed in.
Delegates to the overloaded method that takes a String with multiple delimiters.
str - string to search in. Returns 0 if this is nullplaceholder - the character to search for and count.delim - the delimiter for character literals.
public static int countParameterPlaceholders(java.lang.String str,
char placeholder,
java.lang.String delimiters)
placeholder in an SQL string
str. The character placeholder is not counted if it
appears within a literal as determined by the delimiters that are passed in.
Examples: If one of the delimiters is the single quote, and the character to count the occurrences of is the question mark, then:
The big ? 'bad wolf?' gives a count of one.
The big ?? bad wolf gives a count of two.
The big 'ba''ad?' ? wolf gives a count of one.
The grammar of the string passed in should obey the rules of the JDBC spec which is close to no rules at all: one placeholder per parameter, and it should be valid SQL for the target database.
str - string to search in. Returns 0 if this is nullplaceholder - the character to search for and count.delimiters - the delimiters for character literals.public static boolean isNumeric(int sqlType)
sqlType - the SQL type to be checked
public static int translateType(int sqlType)
sqlType - the type to be translated into a simpler type
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||