Package play.db
Class DB
- java.lang.Object
-
- play.db.DB
-
public class DB extends java.lang.Object
Database connection utilities.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DB.ExtendedDatasource
-
Field Summary
Fields Modifier and Type Field Description static javax.sql.DataSource
datasource
Deprecated.Use datasources insteadprotected static java.util.Map<java.lang.String,DB.ExtendedDatasource>
datasources
The loaded datasource.static java.lang.String
DEFAULT
static java.lang.String
destroyMethod
Deprecated.Use datasources instead
-
Constructor Summary
Constructors Constructor Description DB()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
close()
Close all the open connections for the current thread.static void
close(java.lang.String name)
Close an given open connections for the current threadstatic void
closeAll()
Close all the open connections for the current thread.static void
destroy()
Destroy the datasourcestatic void
destroy(java.lang.String name)
Destroy the datasourcestatic void
destroyAll()
Destroy all datasourcesstatic boolean
execute(java.lang.String SQL)
Execute an SQL updatestatic boolean
execute(java.lang.String name, java.lang.String SQL)
Execute an SQL updatestatic javax.sql.RowSet
executeQuery(java.lang.String SQL)
Execute an SQL querystatic javax.sql.RowSet
executeQuery(java.lang.String name, java.lang.String SQL)
Execute an SQL querystatic java.sql.Connection
getConnection()
static java.sql.Connection
getConnection(java.lang.String name)
Open a connection for the current thread.static java.sql.Connection
getConnection(java.lang.String name, boolean autocommit)
static javax.sql.DataSource
getDataSource()
static javax.sql.DataSource
getDataSource(java.lang.String name)
static void
safeCloseResultSet(java.sql.ResultSet resultSet)
static void
safeCloseStatement(java.sql.Statement statement)
-
-
-
Field Detail
-
datasources
protected static final java.util.Map<java.lang.String,DB.ExtendedDatasource> datasources
The loaded datasource.- See Also:
DB.ExtendedDatasource
-
datasource
@Deprecated public static javax.sql.DataSource datasource
Deprecated.Use datasources instead- Since:
- 1.3.0
- See Also:
datasources
,DB.ExtendedDatasource
-
destroyMethod
@Deprecated public static java.lang.String destroyMethod
Deprecated.Use datasources insteadThe method used to destroy the datasource- Since:
- 1.3.0
- See Also:
datasources
,DB.ExtendedDatasource
-
DEFAULT
public static final java.lang.String DEFAULT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDataSource
public static javax.sql.DataSource getDataSource(java.lang.String name)
-
getDataSource
public static javax.sql.DataSource getDataSource()
-
getConnection
public static java.sql.Connection getConnection(java.lang.String name, boolean autocommit)
-
closeAll
public static void closeAll()
Close all the open connections for the current thread.
-
close
public static void close()
Close all the open connections for the current thread.
-
close
public static void close(java.lang.String name)
Close an given open connections for the current thread- Parameters:
name
- Name of the DB
-
getConnection
public static java.sql.Connection getConnection(java.lang.String name)
Open a connection for the current thread.- Parameters:
name
- Name of the DB- Returns:
- A valid SQL connection
-
getConnection
public static java.sql.Connection getConnection()
-
execute
public static boolean execute(java.lang.String name, java.lang.String SQL)
Execute an SQL update- Parameters:
name
- the DB nameSQL
- the SQL statement- Returns:
- true if the next result is a ResultSet object; false if it is an update count or there are no more results
-
execute
public static boolean execute(java.lang.String SQL)
Execute an SQL update- Parameters:
SQL
- the SQL statement- Returns:
- true if the next result is a ResultSet object; false if it is an update count or there are no more results
-
executeQuery
public static javax.sql.RowSet executeQuery(java.lang.String SQL)
Execute an SQL query- Parameters:
SQL
- the SQL statement- Returns:
- The ResultSet object; false if it is an update count or there are no more results
-
executeQuery
public static javax.sql.RowSet executeQuery(java.lang.String name, java.lang.String SQL)
Execute an SQL query- Parameters:
name
- the DB nameSQL
- the SQL statement- Returns:
- The rowSet of the query
-
safeCloseResultSet
public static void safeCloseResultSet(java.sql.ResultSet resultSet)
-
safeCloseStatement
public static void safeCloseStatement(java.sql.Statement statement)
-
destroy
public static void destroy(java.lang.String name)
Destroy the datasource- Parameters:
name
- the DB name
-
destroy
public static void destroy()
Destroy the datasource
-
destroyAll
public static void destroyAll()
Destroy all datasources
-
-