示例#1
0
  public void insert() throws RowExistsException {
    if (milog.isInfoEnabled()) {
      milog.info("Telefono de: " + telefono.idGeneral);
    }
    try {
      Connection conn = ConnectionManager.getConection();
      Statement stmt = conn.createStatement();
      ResultSet rs = null;

      StringBuffer sqlString = new StringBuffer("INSERT INTO " + nombreTabla);
      sqlString.append(" VALUES (" + MysqlUtils.toMysqlString(telefono.getIdGeneral()) + ", ");
      sqlString.append(MysqlUtils.toMysqlString(telefono.getDescTelefono()) + ", ");
      sqlString.append(MysqlUtils.toMysqlString(telefono.getTelefono()) + ", ");
      sqlString.append(MysqlUtils.toMysqlString(telefono.getTelefono2()) + ")");

      if (milog.isInfoEnabled()) {
        milog.info("comando sql: " + sqlString);
      }
      stmt.execute(sqlString.toString());
    } catch (Exception ex) {
      if (milog.isInfoEnabled()) {
        milog.info("error: " + ex.toString());
      }
      throw new RowExistsException();
    }
  }
示例#2
0
  public void update() throws RowNotFoundException {

    try {
      Connection conn = ConnectionManager.getConection();
      Statement stmt = conn.createStatement();
      ResultSet rs = null;

      StringBuffer sqlString = new StringBuffer("UPDATE" + nombreTabla);
      sqlString.append("set IdGeneral=" + MysqlUtils.toMysqlString(telefono.getIdGeneral()) + ", ");
      sqlString.append(
          "descTelefono=" + MysqlUtils.toMysqlString(telefono.getDescTelefono()) + ", ");
      sqlString.append("telefono=" + MysqlUtils.toMysqlString(telefono.getTelefono()) + ", ");

      sqlString.append("telefono2=" + MysqlUtils.toMysqlString(telefono.getTelefono2()));
      sqlString.append(
          "WHERE IdGeneral="
              + MysqlUtils.toMysqlString(telefono.getIdGeneral())
              + "AND descTelefono="
              + MysqlUtils.toMysqlString(telefono.getDescTelefono()));
      stmt.execute(sqlString.toString());

    } catch (Exception ex) {
      throw new RowNotFoundException();
    }
  }
示例#3
0
  public void select() throws RowNotFoundException {

    try {

      Connection conn = ConnectionManager.getConection();
      Statement stmt = conn.createStatement();
      ResultSet rs = null;

      rs =
          stmt.executeQuery(
              "SELECT * FROM "
                  + nombreTabla
                  + " WHERE idGeneral ="
                  + MysqlUtils.toMysqlString(telefono.getIdGeneral())
                  + "AND descTelefono ="
                  + MysqlUtils.toMysqlString(telefono.getDescTelefono()));
      if (rs.next()) {
        telefono.setIdGeneral(rs.getString("idGeneral"));
        telefono.setDescTelefono(rs.getString("descTelefono"));
        telefono.setTelefono(rs.getString("telefono"));
        telefono.setTelefono2(rs.getString("telefono2"));

      } else {
        throw new RowNotFoundException();
      }

    } catch (Exception ex) {
      System.out.println(ex);
    }
  }