public class SQLConnectionManager extends Base
SQLConnectionManager
provides methods for initializing and getting connections to databases.Modifier and Type | Method and Description |
---|---|
static void | free(java.sql.Connection conn) Frees a connection previously obtained via SQLConnectionManager. |
static java.sql.Connection | getConnection() Gets a new connection to the default database given in the SmartClient configuration file. |
static java.sql.Connection | getConnection(java.lang.String serverName) Gets a new connection to the database given in the SmartClient configuration file by the parameter database name. |
public static java.sql.Connection getConnection() throws java.sql.SQLException
server.properties
configuration file is located in the isomorphicConfig
directory of the SmartClient installation, and contains the connection parameters for the database given by the sql.defaultDatabase
property. This method returns a fresh connection to the database - either borrowed from the pool if connection pooling is switched on, or a completely new connection if pooling is off, or there are no free connections in the pool. The connection returned is not the same connection as that used to implement auto-managed transactions (see DSRequest.shouldJoinTransaction()
), which leads to two considerations
SQLConnectionManager.free(Connection)
to return the connection. Failure to do so will result in a connection leak If you instead want access to the database connection used by the framework for automatically managed transactions, see DataSource.getTransactionObject(com.isomorphic.datasource.DSRequest)
, and also this Showcase example: Transactional User Operations. Note that you should not call free()
on the connection returned by this method - it is managed by the framework.
java.sql.Connection
session with the default databasejava.sql.SQLException
SQLConnectionManager.free(Connection conn)
public static java.sql.Connection getConnection(java.lang.String serverName) throws java.sql.SQLException
server.properties
configuration file is located in the isomorphicConfig
directory of the SmartClient installation, and contains the connection parameters for the database given by name. Note that the same caveats apply to this method as apply to the no-parameter version SQLConnectionManager.getConnection()
serverName
- the name of the database as given in the configuration filejava.sql.Connection
session with the databasejava.sql.SQLException
SQLConnectionManager.free(Connection conn)
public static void free(java.sql.Connection conn) throws java.sql.SQLException
conn
- The Connection object to freejava.sql.SQLException
SQLConnectionManager.getConnection()