Constructor
new Database(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:
Name |
Type |
Description |
source |
DbSource
|
instance of a helma.objectmodel.db.DbSource |
- Source:
Methods
execute(sql) → {int}
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:
Name |
Type |
Description |
sql |
String
|
an SQL statement |
- Source:
Returns:
either the row count for INSERT, UPDATE or
DELETE statements, or 0 for SQL statements that return nothing
-
Type
-
int
getConnection() → {java.sql.Connection}
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.
- Source:
Returns:
the JDBC connection
-
Type
-
java.sql.Connection
getDriverName() → {String}
Return the name of the JDBC driver used by this Database instance.
- Source:
Returns:
the JDBC driver name
-
Type
-
String
getName() → {String}
Return the name of the Helma DbSource object.
- Source:
Returns:
the DbSource name
-
Type
-
String
getProductName() → {String}
Returns the lower case name of the underlying database product.
- Source:
Returns:
the name of the DB product
-
Type
-
String
isMySql() → {boolean}
Returns true if this is a MySQL database.
- Source:
Returns:
true if this is an MySQL database.
-
Type
-
boolean
isOracle() → {boolean}
Returns true if this is an Oracle database.
- Source:
Returns:
true if this is an Oracle database.
-
Type
-
boolean
isPostgreSql() → {boolean}
Returns true if this is a PostgreSQL database.
- Source:
Returns:
true if this is a PostgreSQL database.
-
Type
-
boolean
query(sql) → {Array}
Executes the given SQL statement. The result set is returned
as JavaScript Array containing a JavaScript Object for each result.
Parameters:
Name |
Type |
Description |
sql |
String
|
an SQL query statement |
- Source:
Returns:
an Array containing the result set
-
Type
-
Array
(static) createInstance(driver, url, name, user, password) → {helma.Database}
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:
Name |
Type |
Description |
driver |
String
|
the class name of the JDBC driver. As
shortcuts, the values "mysql", "oracle" and "postgresql" are
recognized. |
url |
String
|
the JDBC URL. |
name |
String
|
the name of the database to use |
user |
String
|
the the username |
password |
String
|
the password |
- Source:
Returns:
a helma.Database instance
-
Type
-
helma.Database
(static) getInstance(name) → {helma.Database}
Get a Database instance using the Database source defined in the
application's db.properties file with the given name.
Parameters:
Name |
Type |
Description |
name |
String
|
the name of the DB source as defined in db.properties |
- Source:
Returns:
a helma.Database instance
-
Type
-
helma.Database