com.caucho.jslib
Class Database

java.lang.Object
  extended by com.caucho.jslib.Database

public class Database
extends java.lang.Object

Encapsulates a database connection for JavaScript.

 var conn = new Database("jdbc/test");
 var rs = conn.query("select NAME from HOUSES");

 while (rs.next())
   out.writeln(rs.get(1) + "<br/>");

 conn.close();
 


Constructor Summary
Database(java.lang.String name)
          Creates a new database looking up the DataSource in JNDI.
 
Method Summary
 void close()
          Close the connection.
 void commit()
          Commits the current connection.
 java.sql.Connection getConnection()
          Returns the JDBC Connection for the database.
 javax.sql.DataSource getDataSource()
          Returns the JDBC DataSource.
 java.sql.Statement getStatement()
          Returns the JDBC Statement for the database.
 java.sql.PreparedStatement prepare(java.lang.String sql)
          Returns the JDBC Statement for the database.
 java.sql.ResultSet query(java.lang.String sql)
          Execute the sql as a query.
 int update(java.lang.String sql)
          Execute the sql as a query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Database

public Database(java.lang.String name)
         throws java.lang.Exception
Creates a new database looking up the DataSource in JNDI.

Parameters:
name - jndi name to the data source
Throws:
java.lang.Exception
Method Detail

query

public java.sql.ResultSet query(java.lang.String sql)
                         throws java.sql.SQLException
Execute the sql as a query.

Throws:
java.sql.SQLException

update

public int update(java.lang.String sql)
           throws java.sql.SQLException
Execute the sql as a query.

Throws:
java.sql.SQLException

getDataSource

public javax.sql.DataSource getDataSource()
                                   throws java.sql.SQLException
Returns the JDBC DataSource. Applications that need direct access to the data source.

Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns the JDBC Connection for the database. Applications that need direct access to the Connection can use this.

Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Commits the current connection.

Throws:
java.sql.SQLException

getStatement

public java.sql.Statement getStatement()
                                throws java.sql.SQLException
Returns the JDBC Statement for the database. Applications that need direct access to the Java Statement can use this.

Throws:
java.sql.SQLException

prepare

public java.sql.PreparedStatement prepare(java.lang.String sql)
                                   throws java.sql.SQLException
Returns the JDBC Statement for the database. Applications that need direct access to the Java Statement can use this.

Throws:
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Close the connection. Automatically closes the ResultSet, Statement and Connection.

Throws:
java.sql.SQLException