|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jalios.util.DBUtil
public class DBUtil
This class provides a set of static methods which perform various utility operations on databases.
| Field Summary | |
|---|---|
static java.lang.String |
REVISION
|
| Constructor Summary | |
|---|---|
DBUtil()
|
|
| Method Summary | |
|---|---|
static void |
addDataSource(java.lang.String name,
javax.sql.DataSource dataSource)
Adds the given data source. |
static java.lang.String |
buildSelectQuery(java.lang.String dataSource,
java.lang.String select,
java.lang.String from,
java.lang.String orderby,
java.lang.String[] whereParams,
java.lang.String[] whereValues,
boolean and)
This convenient method build an SQL Select query from the given parameters. |
static boolean |
checkDataSource(java.lang.String dataSource)
Returns true if the given dataSource is available (i.e. a connection can be open on this dataSource). |
static SQLQueryResult |
executeQuery(java.lang.String dataSource,
java.lang.String sqlQuery,
int maxRows)
This convient method performs a query and return a SQLQueryResult |
static void |
executeUpdate(java.lang.String dataSource,
java.lang.String sql)
This convenient method executes an update (insert/update/delete) in the given dataSource. |
static boolean[] |
getColumnsNumericsMetaData(java.lang.String dataSource,
java.lang.String tables,
java.lang.String[] columns)
This method do a small request to the given database to extract metadata of given columns. |
static java.sql.Connection |
getConnection(java.lang.String dataSource)
Attempts to establish a connection with a given data source. |
static java.sql.Connection |
getConnection(java.lang.String dataSource,
java.lang.String username,
java.lang.String password)
Attempts to establish a connection with a given data source. |
static javax.sql.DataSource |
getDataSource(java.lang.String dataSource)
Lookup for the given data source. |
static java.util.Map<java.lang.String,javax.sql.DataSource> |
getDataSourceMap()
Lookup for all "java:com/env/jdbc/*" data sources declared in the AppServer. |
static java.lang.Object |
getFirstValue(java.sql.Connection conn,
java.lang.String sqlQuery)
This convenient method performs a query then it returns the value of the first column of the first row of the result set |
static java.lang.Object |
getFirstValue(java.lang.String dataSource,
java.lang.String sqlQuery)
This convenient method performs a query then it returns the value of the first column of the first row of the result set. |
static java.lang.Object |
getFirstValue(java.lang.String dataSource,
java.lang.String select,
java.lang.String from,
java.lang.String orderby,
java.lang.String[] whereParams,
java.lang.String[] whereValues,
boolean and)
This convenient method performs a query then it returns the value of the first column of the first row of the result set. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String REVISION
| Constructor Detail |
|---|
public DBUtil()
| Method Detail |
|---|
public static java.util.Map<java.lang.String,javax.sql.DataSource> getDataSourceMap()
getDataSource(String)public static javax.sql.DataSource getDataSource(java.lang.String dataSource)
dataSource - the name of the data source (eg. "jdbc/TestDB")
getDataSourceMap()
public static java.sql.Connection getConnection(java.lang.String dataSource)
throws java.sql.SQLException
dataSource - the name of the data source (eg. "jdbc/TestDB")
java.sql.SQLException
public static java.sql.Connection getConnection(java.lang.String dataSource,
java.lang.String username,
java.lang.String password)
throws java.sql.SQLException
dataSource - the name of the data source (eg. "jdbc/TestDB")username - the database user on whose behalf the connection is being madepassword - the user's password
java.sql.SQLException
public static java.lang.String buildSelectQuery(java.lang.String dataSource,
java.lang.String select,
java.lang.String from,
java.lang.String orderby,
java.lang.String[] whereParams,
java.lang.String[] whereValues,
boolean and)
throws java.sql.SQLException
dataSource - the name of the data source (eg. "jdbc/TestDB")select - the table filed to select or *from - the table name to work with.orderby - the order by parameterwhereParams - an array of parameterswhereValues - an array of parameters valueand - should be 'AND' or 'OR' between parameters
java.sql.SQLException
public static boolean[] getColumnsNumericsMetaData(java.lang.String dataSource,
java.lang.String tables,
java.lang.String[] columns)
throws java.sql.SQLException
"numeric" means Types.BIGINT, Types.INTEGER, Types.SMALLINT, Types.NUMERIC
dataSource - the name of the data source (eg. "jdbc/TestDB")tables - the table namescolumns - the column names
java.sql.SQLException
public static java.lang.Object getFirstValue(java.lang.String dataSource,
java.lang.String select,
java.lang.String from,
java.lang.String orderby,
java.lang.String[] whereParams,
java.lang.String[] whereValues,
boolean and)
throws java.sql.SQLException
dataSource - the name of the data source (eg. "jdbc/TestDB")select - the table filed to select or *from - the table name to work with.orderby - the order by parameterwhereParams - an array of parameterswhereValues - an array of parameters valueand - should be 'AND' or 'OR' between parameters
java.sql.SQLException
public static java.lang.Object getFirstValue(java.lang.String dataSource,
java.lang.String sqlQuery)
throws java.sql.SQLException
dataSource - the name of the data source (eg. "jdbc/TestDB")sqlQuery - the SQL query to be performed
java.sql.SQLException
public static java.lang.Object getFirstValue(java.sql.Connection conn,
java.lang.String sqlQuery)
conn - the JDBC connectionsqlQuery - the SQL query to be performed
public static SQLQueryResult executeQuery(java.lang.String dataSource,
java.lang.String sqlQuery,
int maxRows)
dataSource - the name of the data source (eg. "jdbc/TestDB")sqlQuery - the SQL (SELECT) querymaxRows - the max rows limit; zero means there is no limit
public static void executeUpdate(java.lang.String dataSource,
java.lang.String sql)
dataSource - the data sourcesql - update querypublic static boolean checkDataSource(java.lang.String dataSource)
dataSource - the data source.
public static void addDataSource(java.lang.String name,
javax.sql.DataSource dataSource)
name - the name of the data source.dataSource - the data source.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||