예제 #1
0
  public List<Veiculo> listarPorPlaca(String placa) {
    List<Veiculo> listaVeiculos = new ArrayList<Veiculo>();
    try {
      Connection con = DatabaseConnection.getConnection();
      StringBuffer sb = new StringBuffer();
      sb.append("SELECT * ");
      sb.append("FROM veiculo WHERE placa like ?");

      PreparedStatement st = con.prepareStatement(sb.toString());
      st.setString(1, "%" + placa + "%");
      ResultSet rs = st.executeQuery();
      while (rs.next()) {
        Veiculo v = new Veiculo();
        v.setPlaca(rs.getString("placa"));
        v.setChassi(rs.getString("chassi"));
        v.setMarca(rs.getString("marca"));
        v.setModelo(rs.getString("modelo"));
        v.setAnoFabricacao(rs.getInt("anofabricacao"));
        v.setAnoModelo(rs.getInt("anomododelo"));
        v.setCarroceria(rs.getString("carroceria"));
        v.setCapacidadeCarga(rs.getInt("cap_carga"));
        v.setStatus(rs.getString("status"));
        listaVeiculos.add(v);
      }
      con.close();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return listaVeiculos;
  }
예제 #2
0
  public void alterar(Veiculo v) {
    {
      try {
        Connection con = DatabaseConnection.getConnection();

        StringBuffer sb = new StringBuffer();
        sb.append(
            "UPDATE tb_veiculo SET chassi = ?, marca = ?, modelo = ?, anofabricacao = ?, anomodelo = ?, carroceria = ?, ");
        sb.append("capacidadecarga = ?, status = ? ");
        sb.append("WHERE placa = ?");

        PreparedStatement st = con.prepareStatement(sb.toString());
        st.setString(1, v.getChassi());
        st.setString(2, v.getMarca());
        st.setString(3, v.getModelo());
        st.setInt(4, v.getAnoFabricacao());
        st.setInt(5, v.getAnoModelo());
        st.setString(6, v.getCarroceria());
        st.setInt(7, v.getCapacidadeCarga());
        st.setString(8, v.getStatus());
        st.setString(9, v.getPlaca());

        st.executeUpdate();
        con.close();
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
예제 #3
0
  public void adicionar(Veiculo v) {
    try {
      Connection con = DatabaseConnection.getConnection();
      StringBuffer sb = new StringBuffer();
      sb.append(
          "INSERT INTO tb_veiculo (placa, chassi, marca, modelo, anofabricacao, anomodelo, carroceria, ");
      sb.append("capacidadecarga, status )");
      sb.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");

      PreparedStatement st = con.prepareStatement(sb.toString());
      st.setString(1, v.getPlaca());
      st.setString(2, v.getChassi());
      st.setString(3, v.getMarca());
      st.setString(4, v.getModelo());
      st.setInt(5, v.getAnoFabricacao());
      st.setInt(6, v.getAnoModelo());
      st.setString(7, v.getCarroceria());
      st.setInt(8, v.getCapacidadeCarga());
      st.setString(9, v.getStatus());
      st.executeUpdate();
      con.close();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
예제 #4
0
 public void remover(Veiculo v) {
   try {
     Connection con = DatabaseConnection.getConnection();
     String sql = "DELETE FROM tb_veiculo WHERE placa = ?";
     PreparedStatement st = con.prepareStatement(sql);
     st.setString(1, v.getPlaca());
     st.executeUpdate();
     con.close();
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }