|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.xj.anylogic.engine.connectivity.Database
public final class Database
Database connection manager class
| Field Summary | |
|---|---|
static java.lang.String |
DRIVER_JDBC_MICROSOFT_SQLSERVER
Microsoft SQL Server driver for Java External jar-file is needed to use this driver Driver may be downloaded from www.microsoft.com (use search by "SQL Server Driver for JDBC") |
static java.lang.String |
DRIVER_JTDS_JDBC
Open-source JTDS-JDBC driver External jar-file is needed to use this driver Driver may be downloaded from jtds.sourceforge.net (see "Download" section) |
static java.lang.String |
DRIVER_SUN_JDBC_ODBC
Java JDBC-ODBC bridge driver Driver is usually included into standard JRE installation |
| Constructor Summary | |
|---|---|
Database(Presentable owner,
java.lang.String name,
java.lang.String fileName)
Creates new Database object for interaction with file-based
(Access or Excel) database |
|
Database(Presentable owner,
java.lang.String name,
java.lang.String fileName,
java.lang.String login,
char[] password)
Creates new Database object for interaction with file-based
(Access or Excel) database |
|
Database(Presentable owner,
java.lang.String name,
java.lang.String jdbcDriver,
java.lang.String connectionURL,
java.lang.String login,
char[] password)
Creates new Database object for interaction with database |
|
Database(Presentable owner,
java.lang.String name,
java.lang.String sqlJdbcDriver,
java.lang.String host,
java.lang.String databaseName,
java.lang.String login,
char[] password)
Creates new Database object for interaction with MS SQL Server
database |
|
| Method Summary | |
|---|---|
void |
closeResultSet(ResultSet rs)
Deprecated. call ResultSet.close() method instead |
boolean |
connect()
The method connects a data source, specified by constructor parameters. |
void |
destroy()
Releases resources acquired by this object Also destroys all not destroyed contributors associated with this object Doest nothing if object is already destroyed |
void |
disconnect()
Disconnects currently connected database This method call has no effect if this Database object is not
connectedIt is strongly recommended that user explicitly commits or rolls back an active transaction (if any has been explicitly opened via Connection.setAutoCommit(boolean)) prior to calling the this
method. |
java.sql.Connection |
getConnection()
Returns existing Connection to the database or connects to the
database if not connectedIf any error occurs, throws RuntimeException |
java.lang.Integer |
getFieldType(java.lang.String sTableName,
java.lang.String sFieldName)
The methods returns SQL-type of specified field. |
java.lang.Object |
getMatrix(java.lang.String sqlQuery,
java.lang.String type)
The method executes specified SQL query and returns the produced values as 2D array of values of specified type. |
java.lang.String |
getName()
Returns the name of this object |
ResultSet |
getQueryResultSet(java.lang.String queryText,
java.lang.String listOfFields,
java.lang.String keyField,
java.lang.String keyFieldValue)
The method returns result set produced by querying data from specified fields and rows of specified query. |
ResultSet |
getResultSet(java.lang.String sqlQuery)
The method executes specified SQL query and returns the produced result as ResultSet object. |
java.util.Map<java.lang.String,java.lang.String> |
getRow(java.lang.String sqlQuery)
The method executes specified SQL query and returns the produced values. |
static java.sql.ResultSet |
getSQLResultSet(ResultSet rs)
|
static java.sql.Statement |
getSQLStatement(Statement statement)
Returns Java SQL Statement, backed by given
Statement object |
Statement |
getStatement()
The method creates and returns each time new statement Please call Statement.close() method after all needed operations
are completed |
ResultSet |
getTableResultSet(java.lang.String tableName,
java.lang.String listOfFields,
java.lang.String keyField,
java.lang.String keyFieldValue)
The method returns result set produced by querying data from specified fields and rows of specified table. |
java.lang.String |
getValue(java.lang.String sqlQuery)
The method executes specified SQL query and returns the produced value. |
boolean |
modify(java.lang.String sqlQuery)
The method executes specified SQL query. |
void |
releaseStatement(Statement statement)
Deprecated. call Statement.close() method instead |
void |
restoreOwner(java.lang.Object owner)
This method normally should not be called by user This method restores owner of this object The method is used in snapshot saving/loading |
java.lang.String |
toString()
Returns formatted database connection properties (excluding password value) |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String DRIVER_SUN_JDBC_ODBC
public static final java.lang.String DRIVER_JDBC_MICROSOFT_SQLSERVER
"SQL Server Driver for JDBC")
public static final java.lang.String DRIVER_JTDS_JDBC
"Download" section)
| Constructor Detail |
|---|
public Database(Presentable owner,
java.lang.String name,
java.lang.String jdbcDriver,
java.lang.String connectionURL,
java.lang.String login,
char[] password)
Database object for interaction with database
owner - this object's owner (Active Object or Experiment)name - object name (decoration purpose)jdbcDriver - connectionURL - login - password - the password is copied to internal variable, then given array
is wiped
public Database(Presentable owner,
java.lang.String name,
java.lang.String fileName)
Database object for interaction with file-based
(Access or Excel) database
owner - this object's owner (Active Object or Experiment)name - object name (decoration purpose)fileName - file name with extension .xls or
.mdb
public Database(Presentable owner,
java.lang.String name,
java.lang.String fileName,
java.lang.String login,
char[] password)
Database object for interaction with file-based
(Access or Excel) database
owner - this object's owner (Active Object or Experiment)name - object name (decoration purpose)fileName - file name with extension .xls or
.mdblogin - password -
public Database(Presentable owner,
java.lang.String name,
java.lang.String sqlJdbcDriver,
java.lang.String host,
java.lang.String databaseName,
java.lang.String login,
char[] password)
Database object for interaction with MS SQL Server
database
owner - this object's owner (Active Object or Experiment)name - object name (decoration purpose)sqlJdbcDriver - one of
host - databaseName - login - user name or null for Windows authenticationpassword - password or null for Windows authentication| Method Detail |
|---|
public java.lang.String toString()
public void disconnect()
Database object is not
connectedConnection.setAutoCommit(boolean)) prior to calling the this
method. If this method is called and there is an active transaction, the
results are generally unpredictable.RuntimeException
public java.sql.Connection getConnection()
Connection to the database or connects to the
database if not connectedRuntimeException
nullpublic boolean connect()
true if connection is set properly or already
exists, false otherwise.public Statement getStatement()
Statement.close() method after all needed operations
are completed
public java.lang.String getValue(java.lang.String sqlQuery)
sqlQuery - SQL query to be executed
public java.util.Map<java.lang.String,java.lang.String> getRow(java.lang.String sqlQuery)
Map that contains {"Field name"; "Field value"}
String pairs.
sqlQuery - SQL query to be executed
Map that contains {"Field name"; "Field value"} String
pairs or null if an error occurs or if the query produces no
values
public java.lang.Object getMatrix(java.lang.String sqlQuery,
java.lang.String type)
sqlQuery - SQL query to be executedtype - one of:
"byte"
"short"
"int"
"long"
"float"
"double"
"boolean"
"String"
public ResultSet getTableResultSet(java.lang.String tableName,
java.lang.String listOfFields,
java.lang.String keyField,
java.lang.String keyFieldValue)
tableName - Table namelistOfFields - List of fields (ignored if null)keyField - Name of the key field (ignored if null or if sListOfFields is
null)keyFieldValue - Value of the key field (ignored if null or if sListOfFields is
null)
ResultSet.close() method after all needed
operations are completed
public ResultSet getQueryResultSet(java.lang.String queryText,
java.lang.String listOfFields,
java.lang.String keyField,
java.lang.String keyFieldValue)
queryText - Query textlistOfFields - List of fields (ignored if null)keyField - Name of the key field (ignored if null or if sListOfFields is
null)keyFieldValue - Value of the key field (ignored if null or if sListOfFields is
null)
ResultSet.close() method after all needed
operations are completedpublic ResultSet getResultSet(java.lang.String sqlQuery)
ResultSet object.
sqlQuery - SQL query to be executed
ResultSet produced by specified query or
null if an error occursResultSet.close() method after all needed
operations are completedpublic boolean modify(java.lang.String sqlQuery)
sqlQuery - SQL query to be executed
public java.lang.Integer getFieldType(java.lang.String sTableName,
java.lang.String sFieldName)
sTableName - Table namesFieldName - Field name
null if an error occurspublic void restoreOwner(java.lang.Object owner)
restoreOwner in interface com.xj.anylogic.engine.internal.Childowner - owner of this object, usually ActiveObject,
Experiment or
ShapeGroup@Deprecated public void releaseStatement(Statement statement)
Statement.close() method instead
StatementgetStatement()
statement - a Statement previously obtained through
getStatement()getStatement()@Deprecated public void closeResultSet(ResultSet rs)
ResultSet.close() method instead
ResultSet, obtained using preceding
getTableResultSet(String, String, String, String),
getQueryResultSet(String, String, String, String) or
getResultSet(String) callResultSets are closed automatically on this
Database destroy
rs - public static java.sql.Statement getSQLStatement(Statement statement)
Statement, backed by given
Statement object
statement - the Statement object, obtained by
getStatement()
statementpublic static java.sql.ResultSet getSQLResultSet(ResultSet rs)
public final java.lang.String getName()
public final void destroy()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||