Working with Databases

Documentation home

 

See also:   Understanding Ebase Integration

Configurable Ebase Elements

Here is a brief overview of the Ebase elements used to provide database support.

 

 

 

 

 

 

Direct access from a script

As an alternative to using the elements above, you can also use the Java JDBC API to access a database directly; this option is available from server-side Javascript scripts. For example:

 

// use the getDatabaseConnection method to get a connection for any configured Database Connection (see Ebase Elements above)

var con = system.getDatabaseConnection("EBASE_SAMPLES");

var stmt;

var rs;

try

{

  stmt = con.prepareStatement("select customer_id, name from customer where credit_limit > 9999");

  rs = stmt.executeQuery();

 

  // create an array for the result

  var result = [];

 

  // go through the result set and add each row to the result array

  while (rs.next())

  {

      // create an object for each row

      var row = {};

      row.CUSTOMER_ID = rs.getString("customer_id");

      row.NAME = rs.getString("name");

      result.push(row);

  }

 

  // build a table from the results so they can be displayed

  for each (var row in result)

  {

    tables.CUSTOMERS.insertRow();

    tables.CUSTOMERS.CUSTOMER_ID.value = row.CUSTOMER_ID;

    tables.CUSTOMERS.NAME.value = row.NAME;

  }

}

finally

{

  // it is very important to close any open result sets, statements and connection in this manner

  // otherwise there will be a resource leak.

  if(rs) rs.close();

  if(stmt) stmt.close();

  if(con) con.close();

}