Package org.apache.commons.dbutils

Examples of org.apache.commons.dbutils.QueryRunner


 
  public void updateRecord(String tableName, String primaryKeyName, Map columnMap
  throws ControllerException  {
   
    Connection conn = null;
    QueryRunner queryRunner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new MapHandler();
    String sql = null;

    try {
      conn = dataSource.getConnection();
View Full Code Here


    } catch (SQLException se) {
      System.out.println(se.getMessage());
      return;
    }
   
    QueryRunner runner = new QueryRunner();
    ResultSetHandler rsh = new MapHandler();
    String sql = "select * from Client where (ClientID=1)";
    Map clientMap = null;
    try {
      clientMap = (Map) runner.query(conn, sql, null, rsh);
    } catch (SQLException se) {
      System.out.println(se.getMessage());
      return;
    }
   
    Set fieldSet = clientMap.keySet();
    Iterator iterator = fieldSet.iterator();
    String fieldName = null;
   
    while (iterator.hasNext()) {
      fieldName = (String) iterator.next();
      System.out.println("Field name = " + fieldName);
      System.out.println("Field value = " + clientMap.get(fieldName));
    }
   
    clientMap = null;
    try {
      clientMap = (Map) runner.query(conn, sql, null, rsh);
      DbUtils.close(conn);
    } catch (SQLException se) {
      System.out.println(se.getMessage());
      return;
    }
View Full Code Here

    throws ControllerException {
   
    // Create user in system database as well.
    String sql = "select * from SYS_INFO.sUSRPassword";
    sql += " where (UserName='" + userName + "')";
    QueryRunner queryRunner = new QueryRunner(DataSourceHandler.getDataSource());
    ResultSetHandler rsh = new MapHandler();

    try {
      return (Map) queryRunner.query(sql, rsh);
    } catch (SQLException se) {
      log.warning("SystemDBController: " + se.getMessage());
      throw new ControllerException(se);
    }
  }     
View Full Code Here

   * Cache all parameters
   *
   */
  public static void loadParameters() {

      QueryRunner queryRunner = new QueryRunner(DataSourceHandler.getDataSource());
      ResultSetHandler rsh = new MapListHandler();
      String sql = "select * from parameter";
     
      try {
        parameterMap = (Map) queryRunner.query(sql, rsh);
      } catch (SQLException se) {
        String msg = "Parameter: error loading parameters.\n" + se.getMessage();
        log.warning(msg);
        Messager.exception(null, msg);
        return;
View Full Code Here

  }
 
  public void go() {
   
    DataSource dataSource= DataSourceHandler.getDataSource();
    QueryRunner runner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new ResultSetMetaDataHandler();
    String sql = "select * from Client";
    List columnList = null;
    try {
      columnList = (List) runner.query(sql, rsh);
    } catch (SQLException se) {
      System.out.println(se.getMessage());
      return;
    }
   
View Full Code Here

    String tableName,
    String orderClause,
    String whereClause)
    throws ControllerException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new MapListHandler();
    String sql = null;

    try {
      sql = "SELECT * FROM " + tableName;

      if (whereClause != null) {
        sql += " WHERE (" + whereClause + ")";
      }

      if (orderClause != null) {
        sql += " ORDER BY " + orderClause;
      }

      return (List) queryRunner.query(sql, rsh);
    } catch (SQLException se) {
      log.warning("GenericController SQLException: " + se.getMessage());
      throw new ControllerException(se);
    }
  }
View Full Code Here

   *                 If no record found throw FinderException
   */
  public Map findWhere(String tableName, String whereClause)
    throws ControllerException, FinderException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new MapHandler();
    String sql = null;

    try {
      sql = "SELECT * FROM " + tableName;

      if (whereClause != null) {
        sql += " WHERE " + whereClause;
      }

      Map map = (Map) queryRunner.query(sql, rsh);
      if (map == null) {
        throw new FinderException();
      }

      return map;
View Full Code Here

    String tableName,
    String whereClause,
    Object[] params)
    throws ControllerException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new MapHandler();
    String sql = null;

    try {
      sql = "SELECT * FROM " + tableName;

      if (whereClause != null) {
        sql += " WHERE (" + whereClause + ")";
      }

      Map map = null;
      if (params == null) {
        map = (Map) queryRunner.query(sql, rsh);
      } else {
        map = (Map) queryRunner.query(sql, params, rsh);
      }

      if (map == null) {
        return false;
      } else {
View Full Code Here

    String primaryKeyName,
    Map columnMap)
    throws ControllerException {

    Connection conn = null;
    QueryRunner queryRunner = new QueryRunner(dataSource);
    String sql = null;
    String columnName = null;
    int i;

    try {
      conn = dataSource.getConnection();
      conn.setAutoCommit(false); // start transaction
      // Create primary key in case primary key is null
      if (columnMap.get(primaryKeyName) == null) {
        int uniqueKey = nz.co.transparent.client.db.SQL.getUniqueKey(tableName, primaryKeyName);
        columnMap.put(primaryKeyName, new Integer(uniqueKey));
      }

      sql = "insert into " + tableName;
      String parm = null;
      Set columnSet = columnMap.keySet();
      Iterator iterator = columnSet.iterator();
      List paramList = new ArrayList(columnSet.size());
      i = 0;
      int j = 0;

      while (iterator.hasNext()) {
        columnName = (String) iterator.next();
        // CURRENT_TIMESTAMP must be set directly into SQL to force
        // date created by server
        // Alternatively these columns can be left out of the map
        if (columnName.equals("date_created")) {
          parm = "CURRENT_TIMESTAMP";
        } else if (columnName.equals("date_updated")) {
          parm = "CURRENT_TIMESTAMP";
        } else {
          parm = "?";
          paramList.add(columnMap.get(columnName));
        }

        if (j++ == 0) {
          sql += " set " + columnName + "=" + parm;
        } else {
          sql += " ," + columnName + "=" + parm;
        }
      }

      try {
        i = queryRunner.update(conn, sql, paramList.toArray());
        conn.commit();
        return i;
      } catch (SQLException se) {
        conn.rollback();
        throw new ControllerException(se);
View Full Code Here

   * @throws ControllerException
   */
  public int deleteRecord(String tableName, String whereClause)
    throws ControllerException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    String sql = null;

    try {
      sql = "delete from " + tableName;

      if (whereClause != null) {
        sql += " where " + whereClause;
      }

      return queryRunner.update(sql);
    } catch (SQLException se) {
      log.warning("GenericController SQLException: " + se.getMessage());
      throw new ControllerException(se);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.dbutils.QueryRunner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.