public void actionPerformed(ActionEvent ev) {
        try {
          // stok
          String query = "DELETE FROM stok_produk WHERE id_produk=" + idProduk;
          int hasil1 = stm.executeUpdate(query);

          // pemasukkan
          query = "DELETE FROM pemasukan WHERE id_produk=" + idProduk;
          int hasil2 = stm.executeUpdate(query);

          // pengeluaran
          query = "DELETE FROM pengeluaran WHERE id_produk=" + idProduk;
          int hasil3 = stm.executeUpdate(query);

          // produk
          query = "DELETE FROM produk WHERE id_produk=" + idProduk;
          int hasil4 = stm.executeUpdate(query);

          if (hasil1 == 1 || hasil2 == 1 || hasil3 == 1 && hasil4 == 1) {
            setDataTabel();
            JOptionPane.showMessageDialog(null, "berhasil hapus");
          } else {
            JOptionPane.showMessageDialog(null, "gagal");
          }
        } catch (SQLException SQLerr) {
          SQLerr.printStackTrace();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
Example #2
1
 Query(Connection connection, String query) {
   try {
     statement = connection.prepareStatement(query);
   } catch (SQLException e) {
     throw new SqlException(e.getMessage(), e);
   }
 }
 public String getKnownShipperDetails(String locationCode, String shipperId) {
   Connection connection = null;
   CallableStatement cStmt = null;
   ResultSet rs = null;
   String Code = null;
   try {
     connection = getConnection();
     cStmt = connection.prepareCall("{? = call ETRANS_UTIL.GETKNOWNSHIPPERSTATUS(?,?,?) }");
     cStmt.setString(2, locationCode);
     cStmt.setString(3, shipperId);
     cStmt.setString(4, "OPR");
     cStmt.registerOutParameter(1, java.sql.Types.VARCHAR);
     cStmt.execute();
     Code = cStmt.getString(1);
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     try {
       ConnectionUtil.closeConnection(connection, cStmt, rs);
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
   return Code;
 }
Example #4
1
  @Override
  public long update() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;

    ResultSet rst = null;
    try {
      String sql = UPDATE_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();

      bindVars.add(SQLValue.String(user.getUserName()));
      bindVars.add(SQLValue.String(user.getFirstName()));
      bindVars.add(SQLValue.String(user.getMiddleName()));
      bindVars.add(SQLValue.String(user.getLastName()));
      bindVars.add(SQLValue.String(user.getMailId()));
      bindVars.add(SQLValue.String(user.getPassword()));
      bindVars.add(SQLValue.Blob((Blob) user.getImage()));
      bindVars.add(SQLValue.String(user.getDob()));
      bindVars.add(SQLValue.Long(user.getSex()));
      bindVars.add(SQLValue.Long(user.getAddressId()));
      bindVars.add(SQLValue.String(user.getMaritalStatus()));
      bindVars.add(SQLValue.String(user.getNationality()));
      bindVars.add(SQLValue.Boolean(user.isActive()));
      bindVars.add(SQLValue.String(user.getActivationKey()));
      bindVars.add(SQLValue.Long(user.getId()));

      logger.debug("QUERY - Loading Address :" + sql);
      return executeUpdate(sql, bindVars);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    } finally {
      close(null, rst);
    }
  }
Example #5
1
  public void eliminarConfiguracion(int usuario) throws DAOException {
    log.info("eliminarConfiguracion(int usuario)");
    Connection cons = null;
    PreparedStatement stmt = null;
    try {
      String query = "DELETE FROM cv_servicio_usuario WHERE IDUSUARIO=?";
      cons = dataSource.getConnection();
      stmt = cons.prepareStatement(query);
      stmt.setInt(1, usuario);
      stmt.executeUpdate();

      query =
          "insert into cv_servicio_usuario(idusuario,idservicio,columna,posicion,visible,estado) "
              + "select ?,idservicio,columna,posicion,usuario_visible,usuario_estado "
              + "from cv_servicio_maestro";
      stmt = cons.prepareStatement(query);
      stmt.setInt(1, usuario);
      stmt.executeUpdate();
    } catch (SQLException e) {
      log.info(e.toString());
      throw new DAOException(e.toString());
    } catch (Exception e) {
      log.info(e.toString());
      throw new DAOException(e.toString());
    } finally {
      closeStatement(stmt);
      closeConnection(cons);
    }
  }
Example #6
0
 public int eseguiUpdateStatement(PreparedStatement statement) throws SystemError {
   try {
     return statement.executeUpdate();
   } catch (SQLException ex) {
     throw new SystemError(ex.toString(), MODULO, "eseguiUpdateStatement", ex);
   }
 }
  /*
   wyświetlenie zawartości lodówki w formie listy
  */
  public List<Fridge> getAllProducts(int userid) {
    List<Fridge> products = new ArrayList<Fridge>();

    try {
      PreparedStatement preparedStatement =
          connection.prepareStatement("select * from fridge where userid=?");
      preparedStatement.setInt(1, userid);
      ResultSet rs = preparedStatement.executeQuery();
      // ResultSet rs = preparedStatement.executeQuery();
      // Statement statement = connection.createStatement();
      // ResultSet rs = statement.executeQuery("select * from fridge where userid=?");
      while (rs.next()) {
        // wypełnianie listy
        Fridge product = new Fridge();
        product.setProductID(rs.getInt("ProductID"));
        product.setName(rs.getString("ProductName"));
        product.setAmount(rs.getInt("ProductAmount"));
        product.setUserID(rs.getInt("UserID"));
        products.add(product);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return products;
  }
Example #8
0
  private HashMap<String, String> getLoginInfo(
      String url, String db, String userName, String password) throws SQLException {
    Connection con = null;
    String driver = "com.mysql.jdbc.Driver";
    HashMap<String, String> info = new HashMap<String, String>();
    try {
      Class.forName(driver);
      con = DriverManager.getConnection(url + db, userName, password);
      String selectStatement = "SELECT userId,userName FROM Users";
      Statement st = con.createStatement();
      ResultSet linksRecords = st.executeQuery(selectStatement);

      while (linksRecords.next()) {
        info.put(linksRecords.getString("userId"), linksRecords.getString("userName"));
      }
      linksRecords.close();
    } catch (SQLException s) {
      // System.out.println("SQL statement is not executed!\n"+s.getMessage());
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        con.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return info;
  }
Example #9
0
  private List<LinkCandidate> getLinksCandidates(
      String url, String db, String userName, String password) throws SQLException {
    // JDBCConnectionPool x=new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver",
    // "jdbc:mysql://localhost:3306/", "hgf", "xxxxx");
    List<LinkCandidate> infoList = new ArrayList<LinkCandidate>();
    Connection con = null;
    String driver = "com.mysql.jdbc.Driver";
    try {
      Class.forName(driver);
      con = DriverManager.getConnection(url + db, userName, password);
      String selectStatement = "SELECT * FROM Links";
      Statement st = con.createStatement();
      ResultSet linksRecords = st.executeQuery(selectStatement);

      while (linksRecords.next()) {
        // infoList.add(new
        // LinkCandidate(linksRecords.getString("sourceURI"),linksRecords.getString("destinationURI"), linksRecords.getString("relationMapping")));
      }
      linksRecords.close();
    } catch (SQLException s) {

    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        con.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return infoList;
  }
  public static boolean mailAlreadyExsists(String hash, User user) {

    String sql = "SELECT * FROM mail WHERE hash like '" + hash + "';";

    boolean mail = false;

    ResultSet resultSet;

    try {
      resultSet = getStatement().executeQuery(sql);

      while (resultSet.next()) {
        mail = true;
      }

      resultSet.close();
      getStatement().close();

    } catch (SQLException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }

    return mail;
  }
  public static List<Message> getMessagesByUser(User user) {

    List<Message> messages = new ArrayList<Message>();
    ResultSet resultSet;
    Message message;
    String text, hash;
    int id;
    boolean valid = true;

    String sql = "SELECT * FROM mail WHERE userid = " + user.getId() + " ;";

    try {
      resultSet = getStatement().executeQuery(sql);

      while (resultSet.next()) {
        id = resultSet.getInt("mailid");
        text = resultSet.getString("message");
        hash = resultSet.getString("hash");
        message = Message.create(id, text, text.length(), hash, valid);
        messages.add(message);
      }

      getStatement().close();

    } catch (SQLException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }

    return messages;
  }
  public static void saveMail(User user, Message message) {

    ResultSet resultSet = null;

    try {

      String sql =
          "INSERT INTO mail (mailid,userid,hash,message) values("
              + message.getId()
              + ","
              + user.getId()
              + ",'"
              + message.getHash()
              + "','"
              + message.getContent()
              + "');";

      getStatement().execute(sql);

      resultSet.close();
      getStatement().close();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  @Deprecated
  public static void addNewMessageToUser(User user, Message message) {

    String sql = "SELECT MAX(mailid) as 'maxid' FROM mail;";

    ResultSet resultSet = null;
    int number = 10000;

    try {
      resultSet = getStatement().executeQuery(sql);

      resultSet.next();
      number = resultSet.getInt("maxid");

      number++;
      sql =
          "INSERT INTO mail (mailid,userid,hash,message) values("
              + number
              + ","
              + user.getId()
              + ",'"
              + message.getHash()
              + "','"
              + message.getContent().replace("'", "\"")
              + "');";

      getStatement().execute(sql);

      resultSet.close();
      getStatement().close();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
 /**
  * Close the real JDBC Connection
  *
  * @return
  */
 public void close() {
   try {
     connection.close();
   } catch (SQLException sqle) {
     System.err.println(sqle.getMessage());
   }
 }
 public static void run() {
   MybatisOperation.instance().createTable();
   List<String> warnings = new ArrayList<String>();
   boolean overwrite = true;
   String genCfg = "/generator.xml"; // src的一级目录下
   File configFile = new File(MyBatisGeneratorTool.class.getResource(genCfg).getFile());
   ConfigurationParser cp = new ConfigurationParser(warnings);
   Configuration config = null;
   try {
     config = cp.parseConfiguration(configFile);
   } catch (IOException e) {
     e.printStackTrace();
   } catch (XMLParserException e) {
     e.printStackTrace();
   }
   DefaultShellCallback callback = new DefaultShellCallback(overwrite);
   MyBatisGenerator myBatisGenerator = null;
   try {
     myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
   } catch (InvalidConfigurationException e) {
     e.printStackTrace();
   }
   try {
     myBatisGenerator.generate(null);
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Example #16
0
  private void loadSqlFile(String fileName) throws Exception {
    Statement statement = null;

    try {
      statement = connection.createStatement();

      String commands = getFileContents(fileName);

      for (int targetPos = commands.indexOf(';');
          targetPos > -1;
          targetPos = commands.indexOf(';')) {
        String cmd = commands.substring(0, targetPos + 1);

        try {
          statement.execute(cmd);
        } catch (SQLException sqle) {
          System.out.println("Statement: " + cmd + ": " + sqle.getMessage());
        }

        commands = commands.substring(targetPos + 2);
      }
    } finally {

      if (statement != null) {
        statement.close();
      }
    }
  }
Example #17
0
 public ResultSet eseguiQueryStatement(PreparedStatement statement) throws SystemError {
   try {
     return statement.executeQuery();
   } catch (SQLException ex) {
     throw new SystemError(ex.toString(), MODULO, "eseguiQueryStatement", ex);
   }
 }
  @Override
  protected ResultSet doInBackground(String... strings) {

    String ls_usuario = "pavel";
    String ls_clave = "pavelito";
    String ls_sql = "insert into punto (color,cantidad) values('" + strings[1] + "',1)";

    try {
      Class.forName("com.mysql.jdbc.Driver");
      conexionMysql = DriverManager.getConnection(strings[0], ls_usuario, ls_clave);
      Statement estado = conexionMysql.createStatement();
      estado.execute(ls_sql);
      System.out.println("Conexion realizada");
      conexionMysql.commit();
      conexionMysql.close();

    } catch (ClassNotFoundException e) {
      /*Toast.makeText(getApplicationContext(), "ERROR:" + e.getMessage(), Toast.LENGTH_SHORT).show();*/
      e.printStackTrace();
    } catch (SQLException e) {
      /*Toast.makeText(getApplicationContext(), "ERROR: " + e.getMessage(), Toast.LENGTH_SHORT).show();*/
      e.printStackTrace();
    }

    return null;
  }
Example #19
0
 @Override
 public void columnsForTables(Table table, DatabaseMetaData dbmd) {
   try {
     rs = dbmd.getColumns(null, "%", table.getName(), null);
     ResultSet priamryKeyRs = dbmd.getPrimaryKeys(null, null, table.getName());
     String priamryKey = null;
     while (priamryKeyRs.next()) {
       priamryKey = priamryKeyRs.getString("COLUMN_NAME");
     }
     while (rs.next()) {
       Column column = new Column();
       String name = rs.getString("COLUMN_NAME");
       column.setName(name);
       column.setType(rs.getString("TYPE_NAME"));
       int columnSize = rs.getInt("COLUMN_SIZE");
       int nullable = rs.getInt("nullable");
       column.setNullable(nullable == 1);
       column.setDataSize(columnSize);
       if (column.getName().equals(priamryKey)) {
         column.setPrimaryKey(true);
       }
       table.addColumn(column);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
  public String ConectarBD(String... strings) {

    String ls_usuario = "COMERCIAL";
    String ls_clave = "COMERCIAL";
    String ls_sql = "select pvp from INV_ARTICULO where cod_barras ='" + strings[1] + "'";
    /* String ls_sql = "select pvp from INV_ARTICULO where cod_barras ='9788431681111'";*/

    try {
      Class.forName("oracle.jdbc.OracleDriver");
      conexion = DriverManager.getConnection(strings[0], ls_usuario, ls_clave);
      Statement estado = conexion.createStatement();
      resultado = (ResultSet) estado.executeQuery(ls_sql);
      while (resultado.next()) {
        ls_precio = "Precio: " + resultado.getString(1);
      }

      System.out.println("Conexion realizada " + ls_precio);

      resultado.close();
      estado.close();
      conexion.close();

    } catch (ClassNotFoundException e) {
      /*Toast.makeText(getApplicationContext(), "ERROR:" + e.getMessage(), Toast.LENGTH_SHORT).show();*/
      e.printStackTrace();
    } catch (SQLException e) {
      /*Toast.makeText(getApplicationContext(), "ERROR: " + e.getMessage(), Toast.LENGTH_SHORT).show();*/
      e.printStackTrace();
    }

    return ls_precio;
  }
Example #21
0
  @Override
  public DataModel read() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;

    ResultSet rst = null;
    try {
      String sql = READ_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();
      if (user.getId() > 0) {
        sql += AND + "`ID` = ? ";
        bindVars.add(SQLValue.Long(user.getId()));
      }
      if (user.getUserName() != null) {
        sql += AND + "`USER_NAME` = ? ";
        bindVars.add(SQLValue.String(user.getUserName()));
      }
      if (user.getPassword() != null) {
        sql += AND + "`PASSWORD` = ? ";
        bindVars.add(SQLValue.String(user.getPassword()));
      }
      logger.debug("QUERY - Loading Address :" + sql);
      rst = executeQuery(sql, bindVars);

      return loadUserVO(user, rst);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    } finally {
      close(null, rst);
    }
  }
  private boolean login(String[] part) {
    ResultSet rs = null;

    try {
      rs = beanOracle.selection("PASSWORD", "UTILISATEURS", "LOGIN = '" + part[1] + "'");
    } catch (SQLException e) {
      System.err.println(e.getStackTrace());
    }

    String pwd = null;

    try {
      if (!rs.next()) {
        SendMsg("ERR#Login invalide");
      } else pwd = rs.getString("PASSWORD");
    } catch (SQLException ex) {
      System.err.println(ex.getStackTrace());
    }

    if (pwd.equals(part[2])) {
      SendMsg("ACK");
      return true;
    } else SendMsg("ERR#Mot de passe incorrecte");

    return false;
  }
Example #23
0
 // 创建新表
 public boolean createTable(String tableName) {
   try {
     Connection conn = getConn();
     if (conn != null) {
       StringBuilder sql = new StringBuilder("CREATE TABLE ");
       sql.append(tableName);
       sql.append(" (");
       sql.append("serialno int(11) NOT NULL AUTO_INCREMENT,");
       sql.append("title varchar(128) NOT NULL,");
       sql.append("smalldesc varchar(512) NOT NULL,");
       sql.append("smallurl varchar(256) DEFAULT NULL,");
       sql.append("source varchar(32) NOT NULL,");
       sql.append("releasetime bigint(20) NOT NULL,");
       sql.append("content varchar(128) NOT NULL,");
       sql.append("classify varchar(16) NOT NULL,");
       sql.append("curl varchar(256) NOT NULL,");
       sql.append("createtime varchar(14) NOT NULL,");
       sql.append("PRIMARY KEY (serialno)");
       sql.append(") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=gbk");
       PreparedStatement stat = conn.prepareStatement(sql.toString());
       stat.executeUpdate();
       conn.close();
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return true;
 }
Example #24
0
 static {
   try {
     java.sql.DriverManager.registerDriver(new Driver());
   } catch (java.sql.SQLException E) {
     E.printStackTrace();
   }
 }
Example #25
0
 ////// Renombrar a grabarPortalMaestro()
 public void guardarPortalGestionar(Collection<String[]> array) throws DAOException {
   log.info("guardarPortalGestionar(Collection<String[]> array)");
   Connection cons = null;
   PreparedStatement stmt = null;
   try {
     String query = "update cv_servicio_maestro set columna=? , posicion=? where idservicio=?";
     cons = dataSource.getConnection();
     stmt = cons.prepareStatement(query);
     int posicion = 0;
     for (String[] item : array) {
       stmt.setInt(1, posicion++);
       for (int u = 0; u < item.length; u++) {
         stmt.setInt(2, u);
         stmt.setString(3, item[u]);
         stmt.executeUpdate();
       }
     }
   } catch (SQLException e) {
     log.error(e);
     throw new DAOException(e.toString());
   } catch (Exception e) {
     log.error(e);
     throw new DAOException(e.toString());
   } finally {
     closeStatement(stmt);
     closeConnection(cons);
   }
 }
  /**
   * Updating a given appointment with new values in the persistence.
   *
   * @param appointment which shall be updated must not be null, id must not be null and must not be
   *     changed
   * @return given appointment with updated values
   * @throws PersistenceException if there are complications with the persitance layer
   */
  @Override
  public Appointment update(Appointment appointment) throws PersistenceException {
    LOGGER.info("Updating record in appointment table..");
    try {
      if (appointment == null) {
        LOGGER.error("Update parameter (appointment) was null.");
        throw new PersistenceException("Appointment to be updated must not be null");
      }

      updateStm.setDate(1, new java.sql.Date(appointment.getDatum().getTime()));
      updateStm.setInt(2, appointment.getSession_id());
      updateStm.setInt(3, appointment.getUser_id());
      updateStm.setBoolean(4, appointment.getIsTrained());
      updateStm.setBoolean(5, appointment.getIsDeleted());
      updateStm.setInt(6, appointment.getId());

      updateStm.executeUpdate();

    } catch (SQLException e) {
      LOGGER.error("Failed to update record in appointment table. - " + e.getMessage());
      throw new PersistenceException("Failed to update record in appointment table.", e);
    }

    LOGGER.info("Record successfully updated in appointment table. " + appointment);
    return appointment;
  }
Example #27
0
  @Override
  public Client search(int id) {

    ResultSet resultSet = null;
    try {
      preparedStatement = connection.prepareStatement("SELECT * FROM clients");
      resultSet = preparedStatement.executeQuery();

      while (resultSet.next()) {
        if (Integer.valueOf(resultSet.getString("id_client")) == id) {
          return new Client(
              resultSet.getString("name"),
              resultSet.getString("login"),
              resultSet.getString("phone"),
              resultSet.getString("email"),
              resultSet.getString("password"));
        }
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }

    return null;
  }
  /**
   * Creates a new appointment.
   *
   * @param appointment which shall be inserted into the underlying persistance layer. must not be
   *     null, id must be null
   * @return the given appointment for further usage
   * @throws PersistenceException if there are complications with the persitance layer
   */
  @Override
  public Appointment create(Appointment appointment) throws PersistenceException {
    LOGGER.info("Creating a new appointment in db.. " + appointment);
    try {
      if (appointment == null) {
        LOGGER.error("Create parameter (appointment) was null.");
        throw new PersistenceException("Appointment to be create must not be null");
      }

      Statement appointmentNextValStm = connection.createStatement();
      ResultSet rs_appointmentNextVal =
          appointmentNextValStm.executeQuery("SELECT NEXTVAL('appointment_seq')");
      rs_appointmentNextVal.next();
      appointment.setId(rs_appointmentNextVal.getInt(1));

      createStm.setInt(1, appointment.getId());
      createStm.setDate(2, new java.sql.Date(appointment.getDatum().getTime()));
      createStm.setInt(3, appointment.getSession_id());
      createStm.setInt(4, appointment.getUser_id());
      createStm.setBoolean(5, appointment.getIsTrained());
      createStm.setBoolean(6, appointment.getIsDeleted());

      createStm.execute();
    } catch (SQLException e) {
      LOGGER.error("Failed to create record into appointment table. - " + e.getMessage());
      throw new PersistenceException("Failed to create record into appointment table.", e);
    }

    LOGGER.info("Record successfully created in appointment table.");
    return appointment;
  }
Example #29
0
  /**
   * excluir
   *
   * @param VO Usuario
   * @return boolean
   */
  public static boolean excluir(Usuario usuario) {
    SigeDataBase db = new SigeDataBase();
    try {
      db.getConn().setAutoCommit(false);
      db.prepareStatement("DELETE FROM permissao_usuario WHERE cd_usuario=?");
      db.setInt(1, usuario.getCodigo());
      db.executeUpdate();
      db.getPreparedStatement().close();

      db.prepareStatement("DELETE FROM usuarios WHERE cd_usuario=?");
      db.setInt(1, usuario.getCodigo());
      db.executeUpdate();
      db.getConn().commit();
      db.closeConnection();
      return true;

    } catch (SQLException ex) {
      ex.printStackTrace();
      try {
        db.getConn().rollback();
        db.closeConnection();
      } catch (SQLException ex1) {
        ex1.printStackTrace();
        db.closeConnection();
      }
      return false;
    }
  }
  public int verificaTipo(int idproc, int chave) {
    /*
     *  tipos de retorno
     *  0 - Atividade
     *  1 - Finalização
     *  2 - Link
     *  3 - erro
     *  4 - Raiz
     * */
    if (chave == 0) return 4;
    sql = "SELECT * FROM processo_atividade WHERE IDproc = ? AND chave = ?";
    try {
      if (!FabricaConexoes.verificaConexao()) FabricaConexoes.getConexao();
      stm = FabricaConexoes.returnStatement(sql);
      stm.setInt(1, idproc);
      stm.setInt(2, chave);
      rs = FabricaConexoes.returnResult(stm);
      rs.next();

      if (rs.getInt("idfin") == 0) {
        return 0;
      } else if (rs.getInt("idfin") != 0 && rs.getInt("link") == 0) {
        return 1;
      } else if (rs.getInt("idfin") != 0 && rs.getInt("link") != 0) {
        return 2;
      } else {
        return 3;
      }

    } catch (SQLException s) {
      JOptionPane.showMessageDialog(null, s.getMessage(), "Erro", 0);
      return 3;
    }
  }