## helma.Database

    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.

Defined in Database.js

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

    helma.Database(<DbSource> source)

Constructor for Database objects, providing access through relational databases through JDBC. It is usually simpler to use one of the factory methods createInstance() or getInstance().

Parameters:

`source` - instance of a helma.objectmodel.db.DbSource

Method Detail

### execute

    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. The return value is an integer that indicates the number of rows that were affected by the statement.

Parameters:

`sql` - an SQL statement

Returns:

either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing

### getConnection

    java.sql.Connection getConnection()

Get the java.sql.Connection for this Database instance. This can be used to operate on the connection directly, without going through the helma.Database class.

Returns:

the JDBC connection

### getDriverName

    String getDriverName()

Return the name of the JDBC driver used by this Database instance.

Returns:

the JDBC driver name

### getName

    String getName()

Return the name of the Helma DbSource object.

Returns:

the DbSource name

### getProductName

    String getProductName()

Returns the lower case name of the underlying database product.

Returns:

the name of the DB product

### isMySql

    boolean isMySql()

Returns true if this is a MySQL database.

Returns:

true if this is an MySQL database.

### isOracle

    boolean isOracle()

Returns true if this is an Oracle database.

Returns:

true if this is an Oracle database.

### isPostgreSql

    boolean isPostgreSql()

Returns true if this is a PostgreSQL database.

Returns:

true if this is a PostgreSQL database.

### query

    Array query(<String> sql)

Executes the given SQL statement. The result set is returned as JavaScript Array containing a JavaScript Object for each result.

Parameters:

`sql` - an SQL query statement

Returns:

an Array containing the result set

### createInstance

    <static> helma.Database createInstance(<String> driver, <String> url, <String> name, <String> user, <String> password)

Create a new Database instance using the given parameters.

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.

Parameters:

`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

Returns:

a helma.Database instance

### getInstance

    <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.

Parameters:

`name` - the name of the DB source as defined in db.properties

Returns:

a helma.Database instance

SUMMARY: Constructor | Properties | Methods | DETAIL: Constructor | Properties | Methods

Documentation generated by JSDoc on Thu Apr 5 01:59:00 2007