@Override public int registrarVehiculo(VehiculoDTO v) { int estado = -1; Connection cn = null; PreparedStatement pstm = null; String sql = ""; try { cn = MySqlDBConexion.getConexion(); sql = "insert into vehiculo values(null,?,?,?,?,?)"; pstm = cn.prepareStatement(sql); pstm.setString(1, v.getPlacaVehiculo()); pstm.setString(2, v.getMarcaVehiculo()); pstm.setString(3, v.getModeloVehiculo()); pstm.setInt(4, v.getAnioFabricacionVehiculo()); pstm.setString(5, v.getColorVehiculo()); estado = pstm.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (pstm != null) { pstm.close(); } if (cn != null) { cn.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return estado; }
@Override public int modificarVehiculo(VehiculoDTO v) { int estado = -1; Connection cn = null; PreparedStatement pstm = null; String sql = ""; try { cn = MySqlDBConexion.getConexion(); sql = "update vehiculo " + "set placaVehiculo = ?, marcaVehiculo=?, modeloVehiculo=?, anioFabricacionVehiculo=?, colorVehiculo=? " + "where idVehiculo = ?"; pstm = cn.prepareStatement(sql); pstm.setString(1, v.getPlacaVehiculo()); pstm.setString(2, v.getMarcaVehiculo()); pstm.setString(3, v.getModeloVehiculo()); pstm.setInt(4, v.getAnioFabricacionVehiculo()); pstm.setString(5, v.getColorVehiculo()); pstm.setInt(6, v.getIdVehiculo()); estado = pstm.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (pstm != null) { pstm.close(); } if (cn != null) { cn.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return estado; }