com.interface21.jdbc.util
Class JdbcUtils

java.lang.Object
  |
  +--com.interface21.jdbc.util.JdbcUtils

public class JdbcUtils
extends java.lang.Object


Constructor Summary
JdbcUtils()
           
 
Method Summary
static int countParameterPlaceholders(java.lang.String str, char marker, char delim)
          Count the occurrences of the character marker in a SQL string str.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcUtils

public JdbcUtils()
Method Detail

countParameterPlaceholders

public static int countParameterPlaceholders(java.lang.String str,
                                             char marker,
                                             char delim)
Count the occurrences of the character marker in a SQL string str. Any two consecutive nested occurrences of delimiter inside a substring of the string delimited by delimiter is ignored. Example : select pet_owner from pet, owner where pet_name = 'bodo''ke' and owner.pet_id = pet.pet_id; In this case the pet's name is "bodo'ke".

The character marker is not counted if it appears withing character delimiter. It is also not counted if it is not followed by whitespace (unless it is just before the closing delimiter)

Examples : if the delimiter 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 zero The big 'ba''ad' ? wolf gives a count of one

The grammar of the string passed in should obey the rules string = (marker | stringPart)* stringPart = character | nestedStringPart nestedStringPart = delimiter (character | nestedDelimiter | marker)* delimiter = the delimiter character (normally the apostrophe for SQL strings) nestedDelimiter = 2 consecutive delimiters marker = the character to count the occurrences of character = all other characters

Parameters:
str - string to search in. Returns 0 if this is null
marker - the character to search for.
delim - the delimiter.

isNumeric

public static boolean isNumeric(int sqlType)
Check that a SQL type is numeric
Parameters:
sqlType - the SQL type to be checked
Returns:
true if the type is numeric, false otherwise

translateType

public static int translateType(int sqlType)
Translate a SQL type into one of a few values. All integer types are translated to Integer. All real types are translated to Double. All string types are translated to String. All other types are left untouched.
Parameters:
sqlType - the type to be translated into a simpler type
Returns:
the new SQL type


Rod Johnson and Spring contributors 2001-2003.