Top Description Fields Constructors Methods
org.h2.util

public Class JdbcUtils

extends Object
Class Inheritance
Static Imports
org.h2.util.Bits.LONG_VH_BE

This is a utility class with JDBC helper functions.

Field Summary

Modifier and TypeField and Description
private static boolean
private static String[]
private static HashSet<String>
private static final String[]
public static JavaObjectSerializer
serializer

The serializer to use.

private static final ArrayList<Utils.ClassFactory>
userClassFactories

In order to manage more than one class loader

private static final byte[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
addClassFactory(Utils.ClassFactory
An object that implements ClassFactory
classFactory
)

Add a class factory in order to manage more than one class loader.

private static void
public static void
closeSilently(Statement
the statement or null
stat
)

Close a statement without throwing an exception.

public static void
closeSilently(Connection
the connection or null
conn
)

Close a connection without throwing an exception.

public static void
closeSilently(ResultSet
the result set or null
rs
)

Close a result set without throwing an exception.

public static Object

Returns:

the object
deserialize
(byte[]
the byte array
data
,
JavaObjectSerializer
the object serializer (may be null)
javaObjectSerializer
)

De-serialize the byte array to an object, eventually using the serializer specified by the connection info.

public static ValueUuid

Returns:

the UUID object
deserializeUuid
(byte[]
the byte array
data
)

De-serialize the byte array to a UUID object.

public static Connection

Returns:

the database connection
getConnection
(String
the driver class name
driver
,
String
the database URL
url
,
String
the user name
user
,
String
the password
password
)

Open a new database connection with the given settings.

public static Connection

Returns:

the database connection
getConnection
(String
the driver class name
driver
,
String
the database URL
url
,
String
the user name or null
user
,
String
the password or null
password
,
NetworkConnectionInfo
the network connection information, or null
networkConnectionInfo
,
boolean
whether database creation is forbidden
forbidCreation
)

Open a new database connection with the given settings.

public static String

Returns:

the driver class name
getDriver
(String
the database URL
url
)

Get the driver class name for the given URL, or null if the URL is unknown.

public static ResultSet

Returns:

the metadata
getMetaResultSet
(Connection
the connection
conn
,
String
the SQL statement
sql
)

Get metadata from the database.

public static boolean

Returns:

true if yes
isBuiltIn
(String
the SQL statement
sql
,
String
the prefix
builtIn
)

Check is the SQL string starts with a prefix (case insensitive).

public static void
load(String
the database URL
url
)

Load the driver class for the given URL, if the database URL is known.

public static <
generic return type
Z
>
Class<Z>

Returns:

the class object
loadUserClass
(String
the name of the class
className
)

Load a class, but check if it is allowed to load this class first.

public static void
removeClassFactory(Utils.ClassFactory
Already inserted class factory instance
classFactory
)

Remove a class factory

public static byte[]

Returns:

the byte array
serialize
(Object
the object to serialize
obj
,
JavaObjectSerializer
the object serializer (may be null)
javaObjectSerializer
)

Serialize the object to a byte array, using the serializer specified by the connection info if set, or the default serializer.

public static void
set(PreparedStatement
the prepared statement
prep
,
int
the parameter index
parameterIndex
,
Value
the value
value
,
JdbcConnection
the own connection
conn
)

Set a value as a parameter in a prepared statement.

private static void
setLob(PreparedStatement prep, int parameterIndex, ValueLob value)

private static void
setOther(PreparedStatement prep, int parameterIndex, Value value, JdbcConnection conn)

public static String[]

Returns:

the array
split
(String
the string
s
)

Split the string using the space separator into at least 10 entries.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowAllClassesback to summary
private static boolean allowAllClasses
allowedClassNamePrefixesback to summary
private static String[] allowedClassNamePrefixes
allowedClassNamesback to summary
private static HashSet<String> allowedClassNames
DRIVERSback to summary
private static final String[] DRIVERS
serializerback to summary
public static JavaObjectSerializer serializer

The serializer to use.

userClassFactoriesback to summary
private static final ArrayList<Utils.ClassFactory> userClassFactories

In order to manage more than one class loader

UUID_PREFIXback to summary
private static final byte[] UUID_PREFIX

Constructor Detail

JdbcUtilsback to summary
private JdbcUtils()

Method Detail

addClassFactoryback to summary
public static void addClassFactory(Utils.ClassFactory classFactory)

Add a class factory in order to manage more than one class loader.

Parameters
classFactory:Utils.ClassFactory

An object that implements ClassFactory

addDatabaseMetaDataback to summary
private static void addDatabaseMetaData(SimpleResultSet rs, DatabaseMetaData meta)
closeSilentlyback to summary
public static void closeSilently(Statement stat)

Close a statement without throwing an exception.

Parameters
stat:Statement

the statement or null

closeSilentlyback to summary
public static void closeSilently(Connection conn)

Close a connection without throwing an exception.

Parameters
conn:Connection

the connection or null

closeSilentlyback to summary
public static void closeSilently(ResultSet rs)

Close a result set without throwing an exception.

Parameters
rs:ResultSet

the result set or null

deserializeback to summary
public static Object deserialize(byte[] data, JavaObjectSerializer javaObjectSerializer)

De-serialize the byte array to an object, eventually using the serializer specified by the connection info.

Parameters
data:byte[]

the byte array

javaObjectSerializer:JavaObjectSerializer

the object serializer (may be null)

Returns:Object

the object

Exceptions
DbException:
if serialization fails
deserializeUuidback to summary
public static ValueUuid deserializeUuid(byte[] data)

De-serialize the byte array to a UUID object. This method is called on the server side where regular de-serialization of user-supplied Java objects may create a security hole if object was maliciously crafted. Unlike deserialize(byte[], JavaObjectSerializer), this method does not try to de-serialize instances of other classes.

Parameters
data:byte[]

the byte array

Returns:ValueUuid

the UUID object

Exceptions
DbException:
if serialization fails
getConnectionback to summary
public static Connection getConnection(String driver, String url, String user, String password) throws SQLException

Open a new database connection with the given settings.

Parameters
driver:String

the driver class name

url:String

the database URL

user:String

the user name

password:String

the password

Returns:Connection

the database connection

Exceptions
SQLException:
on failure
getConnectionback to summary
public static Connection getConnection(String driver, String url, String user, String password, NetworkConnectionInfo networkConnectionInfo, boolean forbidCreation) throws SQLException

Open a new database connection with the given settings.

Parameters
driver:String

the driver class name

url:String

the database URL

user:String

the user name or null

password:String

the password or null

networkConnectionInfo:NetworkConnectionInfo

the network connection information, or null

forbidCreation:boolean

whether database creation is forbidden

Returns:Connection

the database connection

Exceptions
SQLException:
on failure
getDriverback to summary
public static String getDriver(String url)

Get the driver class name for the given URL, or null if the URL is unknown.

Parameters
url:String

the database URL

Returns:String

the driver class name

getMetaResultSetback to summary
public static ResultSet getMetaResultSet(Connection conn, String sql) throws SQLException

Get metadata from the database.

Parameters
conn:Connection

the connection

sql:String

the SQL statement

Returns:ResultSet

the metadata

Exceptions
SQLException:
on failure
isBuiltInback to summary
public static boolean isBuiltIn(String sql, String builtIn)

Check is the SQL string starts with a prefix (case insensitive).

Parameters
sql:String

the SQL statement

builtIn:String

the prefix

Returns:boolean

true if yes

loadback to summary
public static void load(String url)

Load the driver class for the given URL, if the database URL is known.

Parameters
url:String

the database URL

loadUserClassback to summary
public static <Z> Class<Z> loadUserClass(String className)

Load a class, but check if it is allowed to load this class first. To perform access rights checking, the system property h2.allowedClasses needs to be set to a list of class file name prefixes.

Parameters
<Z>
generic return type
className:String

the name of the class

Returns:Class<Z>

the class object

Annotations
@SuppressWarnings:unchecked
removeClassFactoryback to summary
public static void removeClassFactory(Utils.ClassFactory classFactory)

Remove a class factory

Parameters
classFactory:Utils.ClassFactory

Already inserted class factory instance

serializeback to summary
public static byte[] serialize(Object obj, JavaObjectSerializer javaObjectSerializer)

Serialize the object to a byte array, using the serializer specified by the connection info if set, or the default serializer.

Parameters
obj:Object

the object to serialize

javaObjectSerializer:JavaObjectSerializer

the object serializer (may be null)

Returns:byte[]

the byte array

setback to summary
public static void set(PreparedStatement prep, int parameterIndex, Value value, JdbcConnection conn) throws SQLException

Set a value as a parameter in a prepared statement.

Parameters
prep:PreparedStatement

the prepared statement

parameterIndex:int

the parameter index

value:Value

the value

conn:JdbcConnection

the own connection

Exceptions
SQLException:
on failure
setLobback to summary
private static void setLob(PreparedStatement prep, int parameterIndex, ValueLob value) throws SQLException
setOtherback to summary
private static void setOther(PreparedStatement prep, int parameterIndex, Value value, JdbcConnection conn) throws SQLException
splitback to summary
public static String[] split(String s)

Split the string using the space separator into at least 10 entries.

Parameters
s:String

the string

Returns:String[]

the array