Package org.h2.util
Class JdbcUtils
java.lang.Object
org.h2.util.JdbcUtils
This is a utility class with JDBC helper functions.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddClassFactory(Utils.ClassFactory classFactory) Add a class factory in order to manage more than one class loader.static voidcloseSilently(Connection conn) Close a connection without throwing an exception.static voidClose a result set without throwing an exception.static voidcloseSilently(Statement stat) Close a statement without throwing an exception.static Objectdeserialize(byte[] data, JavaObjectSerializer javaObjectSerializer) De-serialize the byte array to an object, eventually using the serializer specified by the connection info.static ValueUuiddeserializeUuid(byte[] data) De-serialize the byte array to a UUID object.static ConnectiongetConnection(String driver, String url, String user, String password) Open a new database connection with the given settings.static ConnectiongetConnection(String driver, String url, String user, String password, NetworkConnectionInfo networkConnectionInfo, boolean forbidCreation) Open a new database connection with the given settings.static StringGet the driver class name for the given URL, or null if the URL is unknown.static ResultSetgetMetaResultSet(Connection conn, String sql) Get metadata from the database.static booleanCheck is the SQL string starts with a prefix (case insensitive).static voidLoad the driver class for the given URL, if the database URL is known.static <Z> Class<Z>loadUserClass(String className) Load a class, but check if it is allowed to load this class first.static voidremoveClassFactory(Utils.ClassFactory classFactory) Remove a class factorystatic 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.static voidset(PreparedStatement prep, int parameterIndex, Value value, JdbcConnection conn) Set a value as a parameter in a prepared statement.static String[]Split the string using the space separator into at least 10 entries.
-
Field Details
-
serializer
The serializer to use.
-
-
Method Details
-
addClassFactory
Add a class factory in order to manage more than one class loader.- Parameters:
classFactory- An object that implements ClassFactory
-
removeClassFactory
Remove a class factory- Parameters:
classFactory- Already inserted class factory instance
-
loadUserClass
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.- Type Parameters:
Z- generic return type- Parameters:
className- the name of the class- Returns:
- the class object
-
closeSilently
Close a statement without throwing an exception.- Parameters:
stat- the statement or null
-
closeSilently
Close a connection without throwing an exception.- Parameters:
conn- the connection or null
-
closeSilently
Close a result set without throwing an exception.- Parameters:
rs- the result set or null
-
getConnection
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- the driver class nameurl- the database URLuser- the user namepassword- the password- Returns:
- the database connection
- Throws:
SQLException- on failure
-
getConnection
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- the driver class nameurl- the database URLuser- the user name ornullpassword- the password ornullnetworkConnectionInfo- the network connection information, ornullforbidCreation- whether database creation is forbidden- Returns:
- the database connection
- Throws:
SQLException- on failure
-
getDriver
Get the driver class name for the given URL, or null if the URL is unknown.- Parameters:
url- the database URL- Returns:
- the driver class name
-
load
Load the driver class for the given URL, if the database URL is known.- Parameters:
url- the database URL
-
serialize
Serialize the object to a byte array, using the serializer specified by the connection info if set, or the default serializer.- Parameters:
obj- the object to serializejavaObjectSerializer- the object serializer (may be null)- Returns:
- the byte array
-
deserialize
De-serialize the byte array to an object, eventually using the serializer specified by the connection info.- Parameters:
data- the byte arrayjavaObjectSerializer- the object serializer (may be null)- Returns:
- the object
- Throws:
DbException- if serialization fails
-
deserializeUuid
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. Unlikedeserialize(byte[], JavaObjectSerializer), this method does not try to de-serialize instances of other classes.- Parameters:
data- the byte array- Returns:
- the UUID object
- Throws:
DbException- if serialization fails
-
set
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- the prepared statementparameterIndex- the parameter indexvalue- the valueconn- the own connection- Throws:
SQLException- on failure
-
getMetaResultSet
Get metadata from the database.- Parameters:
conn- the connectionsql- the SQL statement- Returns:
- the metadata
- Throws:
SQLException- on failure
-
isBuiltIn
Check is the SQL string starts with a prefix (case insensitive).- Parameters:
sql- the SQL statementbuiltIn- the prefix- Returns:
- true if yes
-
split
Split the string using the space separator into at least 10 entries.- Parameters:
s- the string- Returns:
- the array
-