DatabaseConnection

This library handle the database tehchnical code and allow a more friendly usage of the MySQL database hidden by jSeduite Web Services.

DataAccessLayer

This class allow services to query the database transparently.

  • void executeVoid(String query):
    • Execute query, and do not handle database response.
  • String extractScalar(String query, String column):
    • Extract the first value present inside a given column for a query
  • String[] extractScalarSet(String query, String column):
    • Same as extractScalar, but returns all values from the response.
  • DalResultSet extractDataSet(String query):
    • Extract a complex result set from the database, following query.

The following example show how to use this library. You can also read the content of some jSeduite Web services which uses the library, the code isn't that complicated to understand !

public boolean isAuthorized(String login, String password) {
  DataAccessLayer dal = new DataAccessLayer();
  String sql = "SELECT `password` FROM `accounts` WHERE `login` = \"" + login + "\";";
  try {
    String data = dal.extractScalar(sql, "password");
    return data.equals(password);
  } catch(Exception e){ 
    return false; 
  }

DalResultSet

This class is a data structure to handle complex result set. The results can be accessed in a sequential way. For the current result, you can extract the content of a column.

  • void next()
    • Go to the next result (can go outside of the ResultSet boundary)
  • void pred()
    • Go to the previous result (can go outside of the ResultSet boundary)
  • int size()
    • Computes the size of the ResultSet
  • String getValue(String name)
    • Extract current result valued for the column name, or return ”” if such a column doesn't exists.

Usage in a Web Service

You just have to add a dependency to the project libraries/DatabaseConnection for your Web Service.

services/libs/databaseconnection.txt · Last modified: 2009/03/12 22:32 by mosser
CC Attribution-Noncommercial-Share Alike 3.0 Unported www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0