public class JdbcUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static JavaObjectSerializer |
serializer
The serializer to use.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addClassFactory(Utils.ClassFactory classFactory)
Add a class factory in order to manage more than one class loader.
|
static void |
closeSilently(java.sql.Connection conn)
Close a connection without throwing an exception.
|
static void |
closeSilently(java.sql.ResultSet rs)
Close a result set without throwing an exception.
|
static void |
closeSilently(java.sql.Statement stat)
Close a statement without throwing an exception.
|
static java.lang.Object |
deserialize(byte[] data,
JavaObjectSerializer javaObjectSerializer)
De-serialize the byte array to an object, eventually using the serializer
specified by the connection info.
|
static ValueUuid |
deserializeUuid(byte[] data)
De-serialize the byte array to a UUID object.
|
static java.sql.Connection |
getConnection(java.lang.String driver,
java.lang.String url,
java.lang.String user,
java.lang.String password)
Open a new database connection with the given settings.
|
static java.sql.Connection |
getConnection(java.lang.String driver,
java.lang.String url,
java.lang.String user,
java.lang.String password,
NetworkConnectionInfo networkConnectionInfo,
boolean forbidCreation)
Open a new database connection with the given settings.
|
static java.lang.String |
getDriver(java.lang.String url)
Get the driver class name for the given URL, or null if the URL is
unknown.
|
static java.sql.ResultSet |
getMetaResultSet(java.sql.Connection conn,
java.lang.String sql)
Get metadata from the database.
|
static boolean |
isBuiltIn(java.lang.String sql,
java.lang.String builtIn)
Check is the SQL string starts with a prefix (case insensitive).
|
static void |
load(java.lang.String url)
Load the driver class for the given URL, if the database URL is known.
|
static <Z> java.lang.Class<Z> |
loadUserClass(java.lang.String className)
Load a class, but check if it is allowed to load this class first.
|
static void |
removeClassFactory(Utils.ClassFactory classFactory)
Remove a class factory
|
static byte[] |
serialize(java.lang.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 void |
set(java.sql.PreparedStatement prep,
int parameterIndex,
Value value,
JdbcConnection conn)
Set a value as a parameter in a prepared statement.
|
static java.lang.String[] |
split(java.lang.String s)
Split the string using the space separator into at least 10 entries.
|
public static JavaObjectSerializer serializer
public static void addClassFactory(Utils.ClassFactory classFactory)
classFactory - An object that implements ClassFactorypublic static void removeClassFactory(Utils.ClassFactory classFactory)
classFactory - Already inserted class factory instancepublic static <Z> java.lang.Class<Z> loadUserClass(java.lang.String className)
Z - generic return typeclassName - the name of the classpublic static void closeSilently(java.sql.Statement stat)
stat - the statement or nullpublic static void closeSilently(java.sql.Connection conn)
conn - the connection or nullpublic static void closeSilently(java.sql.ResultSet rs)
rs - the result set or nullpublic static java.sql.Connection getConnection(java.lang.String driver,
java.lang.String url,
java.lang.String user,
java.lang.String password)
throws java.sql.SQLException
driver - the driver class nameurl - the database URLuser - the user namepassword - the passwordjava.sql.SQLException - on failurepublic static java.sql.Connection getConnection(java.lang.String driver,
java.lang.String url,
java.lang.String user,
java.lang.String password,
NetworkConnectionInfo networkConnectionInfo,
boolean forbidCreation)
throws java.sql.SQLException
driver - the driver class nameurl - the database URLuser - the user name or nullpassword - the password or nullnetworkConnectionInfo - the network connection information, or nullforbidCreation - whether database creation is forbiddenjava.sql.SQLException - on failurepublic static java.lang.String getDriver(java.lang.String url)
url - the database URLpublic static void load(java.lang.String url)
url - the database URLpublic static byte[] serialize(java.lang.Object obj,
JavaObjectSerializer javaObjectSerializer)
obj - the object to serializejavaObjectSerializer - the object serializer (may be null)public static java.lang.Object deserialize(byte[] data,
JavaObjectSerializer javaObjectSerializer)
data - the byte arrayjavaObjectSerializer - the object serializer (may be null)DbException - if serialization failspublic static ValueUuid deserializeUuid(byte[] data)
deserialize(byte[], JavaObjectSerializer), this method
does not try to de-serialize instances of other classes.data - the byte arrayDbException - if serialization failspublic static void set(java.sql.PreparedStatement prep,
int parameterIndex,
Value value,
JdbcConnection conn)
throws java.sql.SQLException
prep - the prepared statementparameterIndex - the parameter indexvalue - the valueconn - the own connectionjava.sql.SQLException - on failurepublic static java.sql.ResultSet getMetaResultSet(java.sql.Connection conn,
java.lang.String sql)
throws java.sql.SQLException
conn - the connectionsql - the SQL statementjava.sql.SQLException - on failurepublic static boolean isBuiltIn(java.lang.String sql,
java.lang.String builtIn)
sql - the SQL statementbuiltIn - the prefixpublic static java.lang.String[] split(java.lang.String s)
s - the string