Object | +--helma.Database
This class provides access to a relational database through JDBC. There are two convenient ways to create instances of this class.
The first is to use helma.Database.getInstance() to obtain a connection to a DB that is defined in the application's db.properties and managed by Helma. The second way is to define and create a database connection locally using helma.Database.createInstance() and passing it all necessary parameters.
This class provides two ways of interaction: The query() method allows to issue SQL queries, returning a result set. The execute() provides a way to issue SQL statements that do not return a result set.
Database connections allocated by this class are be managed and eventually disposed by Helma.
| SUMMARY: Constructor | Properties | Methods | DETAIL: Constructor | Properties | Methods |
| Constructor Summary | |
helma.Database(<DbSource> source)
Constructor for Database objects, providing access through relational databases through JDBC. |
|
| Methods Summary | |
int
|
execute(<String> sql)
Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL data definition statement. |
java.sql.Connection
|
getConnection()
Get the java.sql.Connection for this Database instance. |
String
|
getDriverName()
Return the name of the JDBC driver used by this Database instance. |
String
|
getName()
Return the name of the Helma DbSource object. |
String
|
getProductName()
Returns the lower case name of the underlying database product. |
boolean
|
isMySql()
Returns true if this is a MySQL database. |
boolean
|
isOracle()
Returns true if this is an Oracle database. |
boolean
|
isPostgreSql()
Returns true if this is a PostgreSQL database. |
Array
|
query(<String> sql)
Executes the given SQL statement. |
<static> helma.Database
|
createInstance(<String> driver, <String> url, <String> name, <String> user, <String> password)
Create a new Database instance using the given parameters. |
<static> helma.Database
|
getInstance(<String> name)
Get a Database instance using the Database source defined in the application's db.properties file with the given name. |
| Constructor Detail |
helma.Database(<DbSource> source)
source - instance of a helma.objectmodel.db.DbSource
| Method Detail |
int execute(<String> sql)
sql - an SQL statement
java.sql.Connection getConnection()
String getDriverName()
String getName()
String getProductName()
boolean isMySql()
boolean isOracle()
boolean isPostgreSql()
Array query(<String> sql)
sql - an SQL query statement
<static> helma.Database createInstance(<String> driver, <String> url, <String> name, <String> user, <String> password)
Some of the parameters support shortcuts for known database products.
The url parameter recognizes the values "mysql", "oracle" and
"postgresql". For those databases, it is also possible to pass just
hostname or hostname:port as url
parameters instead of the full JDBC URL.
driver - the class name of the JDBC driver. As shortcuts, the values "mysql", "oracle" and "postgresql" are recognized.
url - the JDBC URL.
name - the name of the database to use
user - the the username
password - the password
<static> helma.Database getInstance(<String> name)
name - the name of the DB source as defined in db.properties
| SUMMARY: Constructor | Properties | Methods | DETAIL: Constructor | Properties | Methods |