public ArrayList<DetalleFactura> buscar(Factura entidad) throws Exception { ArrayList<DetalleFactura> lista = new ArrayList<DetalleFactura>(); try { cnn = Conexion.getConexion(); CallableStatement cs = null; cs = cnn.prepareCall("call uspListDetalleFactrua(?)"); cs.setInt(1, entidad.getIdFactura()); rs = cs.executeQuery(); while (rs.next()) { DetalleFactura objeto = new DetalleFactura(); objeto.setIdDetalleFactura(rs.getInt("Iddetallefactura")); objeto.setIdProducto(rs.getInt("Idproducto")); objeto.setCantidad(rs.getInt("Cantidad")); objeto.setPrecio(rs.getDouble("Precio")); objeto.setSubTotal(rs.getDouble("Subtotal")); objeto.setIdFactura(rs.getInt("Idfactura")); objeto.setDProducto(rs.getString("DProducto")); lista.add(objeto); } cnn.close(); cs.close(); } catch (SQLException ex) { throw ex; } return lista; }
public boolean save() throws ClassNotFoundException, SQLException { Connection con = Conexion.abrirConexion(); ConsultaSegura.hacerConsulta( con, "insert into " + tabladb + " values(?,?,?,?,?,?,?)", this.toArray()); Conexion.cerrarConexion(con); return true; }
private void insertarSolicitud() { int cliente = buscaCodClient(cboCliente.getSelectedItem().toString(), "cliente"); try { // Insertar Solicitud String sql = "INSERT INTO pedido (id, fecha, cliente, fechapedido) VALUES (NULL, '" + z.dateFormat(calFecha.getDate()) + cliente + "', NOW())"; z.snt = z.con.createStatement(); z.snt.executeUpdate(sql); // insertar ítem for (int fila = 0; fila < tabla.getRowCount(); fila++) { try { String sqlitem = "INSERT INTO detallepedido (pedido, articulo, cantidad) VALUES (" + modelo.getValueAt(fila, 0) + ", LAST_INSERT_ID(), " + modelo.getValueAt(fila, 2) + ")"; z.snt = z.con.createStatement(); z.snt.executeUpdate(sqlitem); } catch (SQLException ex) { Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex); } } } catch (SQLException ex) { Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex); } }
@Override public ArrayList<Persona> listado(String valor) { Conexion con = new Conexion(); con.conectate(); Connection conx = con.getConn(); ArrayList<Persona> resultado = new ArrayList(); String sql = ""; if (valor.equals("")) { sql = "SELECT * FROM Alumno"; } else { sql = "SELECT * FROM Alumno WHERE matricula like '%" + valor + "%'"; } System.out.println(sql); try { Statement st = conx.createStatement(); ResultSet res = st.executeQuery(sql + " order by idAlumno"); while (res.next()) { Persona persona = new Alumno(res.getInt("idAlumno")); resultado.add(persona); } conx.close(); } catch (Exception e) { System.out.println(e.getMessage()); } return resultado; }
public boolean modificarVenta( int pIdVenta, Socio pSocio, Date pFecha, Producto pProducto, TipoPago pTipoPago, boolean pPagado) { boolean exito = true; int numFilas; conexion = new Conexion(); String consulta = "UPDATE VENTA SET VENTA_SOCIO =" + pSocio.getIdSocio() + ", VENTA_FECHA='" + pFecha + "', VENTA_PRODUCTO_ID=" + pProducto.getIdProducto() + ", VENTA_TIPO_PAGO_ID =" + pTipoPago.getIdTipoPago() + ", VENTA_PAGADO=" + pPagado + " WHERE VENTA_ID=" + pIdVenta; try { numFilas = conexion.getStatement().executeUpdate(consulta); if (numFilas == 0) exito = false; } catch (SQLException ex) { System.out.println("No se ha podido realizar la modificación."); } finally { conexion.cerrar(); return exito; } }
@Override public void recibir(Conexion conexion, int respuesta) { if (respuesta == 0) { conexion.setEstado(new Preparado()); } else { conexion.setEstado(new Cerrado()); } }
/** Creates new form ViewCajeroBuscarProducto */ public ViewAdminAlmacenInventario(String cedula) { initComponents(); LabelNumCedula.setVisible(false); Conexion manager = new Conexion(); String queryInventario = "select cod, descripcion, minimo, existencia, medida, costo, precio1, precio2, precio3, impuesto, descuento, ubicacion from producto order by cod ASC;"; manager.llenarTabla(queryInventario, TableInventario); }
public static void main(String args[]) { Conexion bd = new Conexion(); bd.conectar(); Conaic_Area x = new Conaic_Area(bd); x.Buscar("1"); bd.desconectar(); }
public boolean save() throws ClassNotFoundException, SQLException { Connection con = Conexion.abrirConexion(); ConsultaSegura.hacerConsulta( con, "insert into " + tabladb + " (titulo,mensaje,tiene_imagen,nombre_usuario,fecha_evento,hora_inicio,hora_fin) values(?,?,?,?,?,?,?)", this.toArray()); Conexion.cerrarConexion(con); return true; }
public static void main(String args[]) { Conexion bd = new Conexion(); bd.conectar(); Modulo x; x = new Modulo(bd); // x.Buscar(2); // System.out.println(x.getNombre()); bd.desconectar(); }
public boolean agregar(Persona objP) throws Exception { Boolean ok = false; String sql = null; CallableStatement cs = null; Statement st; try { sql = "INSERT INTO persona( apellidos, nombres, fechanacimiento, sexo, tipodocumento, " + " numerodocumento, estadocivil, telefono, movil, correo) VALUES( '" + objP.getApellidos() + "' , '" + objP.getNombres() + "' , '" + objP.getFechaNacimiento() + "' , '" + objP.getSexo() + "' , '" + objP.getTipoDocumento() + "' , '" + objP.getNumeroDocumento() + "' , '" + objP.getEstadoCivil() + "' , '" + objP.getTelefono() + "' , '" + objP.getMovil() + "' , '" + objP.getCorreo() + "' )"; st = conex.Conectar().createStatement(); st.executeUpdate(sql); // cs = conex.Conectar().prepareCall("{ call fu_iPersona (?,?,?,?,?,?,?,?,?,?) }"); // cs.setString(1, objP.getApellidos()); // cs.setString(2, objP.getNombres()); // cs.setDate(3, objP.getFechaNacimiento()); // //cs.setCharacterStream(4, objP.getSexo()); // cs.setString(5, objP.getTipoDocumento()); // cs.setString(6, objP.getNumeroDocumento()); // //cs.setsetChar(7, objP.getEstadoCivil()); // cs.setString(8, objP.getTelefono()); // cs.setString(9, objP.getMovil()); // cs.setString(10, objP.getCorreo()); // // cs.executeUpdate(); ok = true; } catch (Exception e) { throw e; } finally { conex.Desconectar(); conex = null; } return ok; }
public List buscar(Class object, Criteria criterio) { Conexion.getInstancia().iniciarTX(); List<ObjetoPersitente> lista = null; try { lista = criterio.list(); } catch (SQLGrammarException ex) { System.out.println(ex.getMessage()); } Conexion.getInstancia().confirmarTx(); return lista; }
public static boolean delete(String using, String where, ArrayList<String> datos) throws ClassNotFoundException { Connection con = Conexion.abrirConexion(); if (con != null) { ConsultaSegura.hacerConsulta( con, "delete from " + tabladb + " " + using + " where " + where, datos); Conexion.cerrarConexion(con); return true; } else { return false; } }
public ResultSet Buscar(int idAnticipo) { try { conex.conectar(); conn = conex.obtenerConexion(); Statement Comando = conn.createStatement(); Consulta = Comando.executeQuery("select * from anticipos where idAnticipo =" + idAnticipo); return Consulta; } catch (Exception E) { return Consulta; } }
private void cargaCliente() { try { String sql = "SELECT concat(aombre, ' ', apellido) as cliente FROM cliente order by apellido "; z.snt = z.con.createStatement(); z.rs = z.snt.executeQuery(sql); cboCliente.removeAllItems(); while (z.rs.next()) { cboCliente.addItem(z.rs.getString("cliente")); } } catch (SQLException ex) { Logger.getLogger(FrmPedido.class.getName()).log(Level.SEVERE, null, ex); } }
public static ArrayList<Evento> get(String select, String complex, ArrayList<String> datos) throws ClassNotFoundException, NumberFormatException, SQLException { Connection con = Conexion.abrirConexion(); ArrayList<Evento> reg = new ArrayList<Evento>(); if (con != null) { ResultSet res = ConsultaSegura.hacerConsulta( con, "select " + select + " from " + tabladb + " " + (complex.equals("") ? " " : complex), datos); while (res.next()) { Evento r = new Evento(); try { r.setTitulo(res.getString("titulo")); } catch (SQLException e) { } try { r.setMensaje(res.getString("mensaje")); } catch (SQLException e) { } try { r.setTieneImagen(res.getBoolean("tiene_imagen")); } catch (SQLException e) { } try { r.setNombreUsuario(res.getString("nombre_usuario")); } catch (SQLException e) { } try { r.setFechaEvento(res.getDate("fecha_evento")); } catch (SQLException e) { } try { r.setHoraInicio(res.getTime("hora_inicio")); } catch (SQLException e) { } try { r.setHoraFin(res.getTime("hora_fin")); } catch (SQLException e) { } r.setId(res.getInt("id")); reg.add(r); } Conexion.cerrarConexion(con); return reg; } else { return null; } }
public boolean eliminarVenta(int pIdVenta) { boolean exito = true; int numFilas; conexion = new Conexion(); String consulta = "DELETE FROM VENTA WHERE VENTA_ID=" + pIdVenta; try { numFilas = conexion.getStatement().executeUpdate(consulta); if (numFilas == 0) exito = false; } catch (SQLException ex) { System.out.println("No se ha podido realizar la eliminación."); } finally { conexion.cerrar(); return exito; } }
@Override public void eliminar() { Conexion con = new Conexion(); con.conectate(); Connection conx = con.getConn(); try { Statement st = conx.createStatement(); st.execute("delete from alumno where idAlumno=" + this.getId()); conx.close(); } catch (Exception e) { System.out.println(e.getMessage()); } }
/** * Guarda un objeto en la base de datos: actualiza si el objeto ya tiene oid * * @param obj * @throws Exception */ public void guardar(ObjetoPersitente obj) throws Exception { Conexion.getInstancia().iniciarTX(); em = Conexion.getInstancia().getEntityManager(); try { if (obj.getId() != null) { em.merge(obj); } else { em.persist(obj); } Conexion.getInstancia().confirmarTx(); } catch (Exception ex) { ex.printStackTrace(); System.out.println("error"); } }
public static ArrayList<Registrado> get(String select, String complex, ArrayList<String> datos) throws ClassNotFoundException, NumberFormatException, SQLException { Connection con = Conexion.abrirConexion(); ArrayList<Registrado> reg = new ArrayList<Registrado>(); if (con != null) { ResultSet res = ConsultaSegura.hacerConsulta( con, "select " + select + " from " + tabladb + " " + (complex.equals("") ? "" : complex), datos); while (res.next()) { Registrado r = new Registrado(); try { r.setNombreUsuario(res.getString("nombre_usuario")); } catch (SQLException e) { } try { r.setNombre(res.getString("nombre")); } catch (SQLException e) { } try { r.setApellido(res.getString("apellido")); } catch (SQLException e) { } try { r.setEdad(Integer.parseInt(res.getString("edad"))); } catch (SQLException e) { } try { r.setCorreo(res.getString("correo")); } catch (SQLException e) { } try { r.setClave(res.getString("clave")); } catch (SQLException e) { } try { r.setImagenPerfil(res.getString("imagen_perfil")); } catch (SQLException e) { } reg.add(r); } Conexion.cerrarConexion(con); return reg; } else { return null; } }
public void modificar(Persona objP) throws Exception { Statement st = null; String sql = null; try { sql = "UPDATE persona SET " + " apellidos = '" + objP.getApellidos() + "', " + " nombres = '" + objP.getNombres() + "', " + " fechanacimiento = '" + objP.getFechaNacimiento() + "', " + " sexo = '" + objP.getSexo() + "', " + " tipodocumento = '" + objP.getTipoDocumento() + "', " + " numerodocumento = '" + objP.getNumeroDocumento() + "', " + " estadocivil = '" + objP.getEstadoCivil() + "', " + " telefono = '" + objP.getTelefono() + "', " + " movil = '" + objP.getMovil() + "', " + " correo = '" + objP.getCorreo() + "' " + " WHERE codigo = " + objP.getCodigo(); st = conex.Conectar().createStatement(); st.executeUpdate(sql); } catch (Exception e) { throw e; } finally { conex.Desconectar(); conex = null; } }
public Venta getVenta(int pIdVenta) { conexion = new Conexion(); Venta unaVenta = null; Socio unSocio = null; Producto unProducto = null; TipoPago unTipoPago = null; ProductoDAL productoDAL = new ProductoDAL(); TipoPagoDAL tipoPagoDAL = new TipoPagoDAL(); SocioDAL socioDAL = new SocioDAL(); String consulta = "SELECT * FROM VENTA WHERE VENTA_ID = " + pIdVenta; ResultSet rs = null; try { rs = conexion.getStatement().executeQuery(consulta); if (rs.next()) { unSocio = socioDAL.getSocio(rs.getInt("VENTA_SOCIO_ID")); unProducto = productoDAL.getProducto(rs.getInt("VENTA_PRODUCTO_ID")); unTipoPago = tipoPagoDAL.getTipoPago(rs.getInt("VENTA_TIPO_PAGO_ID")); unaVenta = new Venta( rs.getInt("VENTA_ID"), unSocio, rs.getDate("VENTA_FECHA"), unProducto, unTipoPago, rs.getBoolean("VENTA_PAGADO"), rs.getInt("VENTA_UNIDADES"), rs.getDouble("VENTA_IMPORTE"), rs.getString("VENTA_SOCIO_NOMBRE"), rs.getString("VENTA_SOCIO_APELLIDOS"), rs.getString("VENTA_CATEGORIA"), rs.getString("VENTA_SUBCATEGORIA"), rs.getString("VENTA_PRODUCTO_NOMBRE")); } } catch (Exception e) { unaVenta = null; } finally { if (rs != null) { try { rs.close(); } catch (SQLException ex) { System.out.println("No se ha podido cerrar el ResulSet."); } } conexion.cerrar(); return unaVenta; } }
public int giveNumberOfVisits(int id) { int filas = 0; Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = Conexion.getInstance().getConnection(); stmt = conn.createStatement(); String query = "SELECT count(*) as numero_filas " + "FROM patient p,visit v, sucursalroom sr, sucursal s " + "WHERE sr.id_r=p.id_r AND s.id_s=sr.id_s AND p.id_p=v.id_p " + "AND p.ci='" + id + "'"; rs = stmt.executeQuery(query); rs.next(); filas = rs.getInt("numero_filas"); rs.close(); stmt.close(); conn.close(); } catch (SQLException e) { System.err.println(e); } return filas; }
public List<String> getPatients(String patientName, String sucName) { List<String> list = new ArrayList<String>(); Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = Conexion.getInstance().getConnection(); stmt = conn.createStatement(); String query = "SELECT p.name " + "FROM patient p, sucursal s, sucursalroom sr " + "WHERE sr.id_r=p.id_r AND sr.id_s=s.id_s AND " + "s.name='" + sucName + "' AND p.name LIKE '%" + patientName + "%'"; rs = stmt.executeQuery(query); while (rs.next()) { String patName = rs.getString("name"); list.add(patName); } rs.close(); stmt.close(); conn.close(); } catch (SQLException ex) { System.out.println(ex); } return list; }
public int getID_Room(String sucursal, String room) { int id = 0; Connection conn = null; ResultSet rs = null; try { conn = Conexion.getInstance().getConnection(); Statement stmt = conn.createStatement(); String query = "SELECT sr.id_r " + "FROM sucursalroom sr, sucursal s " + "WHERE s.id_s=sr.id_s AND sr.nameroom='" + room + "' AND s.name='" + sucursal + "'"; rs = stmt.executeQuery(query); rs.next(); id = rs.getInt("id_r"); rs.close(); stmt.close(); conn.close(); } catch (SQLException ex) { System.out.println(ex); } return id; }
public Object[][] recieveHistorial(int id, int filas) { Object[][] matriz = null; Connection conn = null; Statement stmt = null; ResultSet rs = null; int x = 0; try { conn = Conexion.getInstance().getConnection(); stmt = conn.createStatement(); String query = "SELECT p.name, p.ci, sr.nameroom, v.visitdate " + "FROM patient p, visit v, sucursalroom sr, sucursal s " + "WHERE sr.id_r=p.id_r AND s.id_s=sr.id_s AND p.id_p=v.id_p " + "AND p.ci='" + id + "'"; rs = stmt.executeQuery(query); matriz = new Object[filas][5]; while (rs.next()) { matriz[x][0] = x + 1; matriz[x][1] = rs.getString("name"); matriz[x][2] = rs.getInt("ci"); matriz[x][3] = rs.getString("nameroom"); matriz[x][4] = rs.getDate("visitdate"); x++; } rs.close(); stmt.close(); conn.close(); } catch (SQLException e) { System.err.print(e); } return matriz; }
@Override public Trago GetById(int id) throws Exception { try { Connection con = Conexion.getConexion(); Statement sql = con.createStatement(); ResultSet cmd = sql.executeQuery("Select * from tragos where id=" + id + ";"); Trago tr = null; while (cmd.next()) { tr = new Trago(); tr.setDescripcion(cmd.getString("descripcion")); tr.setId(cmd.getInt("id")); tr.setEstado((cmd.getInt("estado") == 1) ? true : false); tr.setGraduacion(cmd.getString("graduacion")); tr.setModoPreparacion(cmd.getString("modopreparacion")); tr.setNombre(cmd.getString("nombre")); tr.setPositivo(cmd.getInt("positivo")); tr.setNegativo(cmd.getInt("negativo")); } cmd.close(); sql.close(); con.close(); if (tr != null) { tr.setReceta(ADReceta.getInstancia().GetAllByIdTrago(tr.getId())); } return tr; } catch (Exception ex) { throw ex; } }
@Override public ArrayList<Trago> GetAll() throws Exception { ArrayList<Trago> colTragos = new ArrayList<Trago>(); try { Connection con = Conexion.getConexion(); Statement sql = con.createStatement(); ResultSet cmd = sql.executeQuery("Select * from tragos;"); while (cmd.next()) { Trago tr = new Trago(); tr.setDescripcion(cmd.getString("descripcion")); tr.setId(cmd.getInt("id")); tr.setEstado((cmd.getInt("estado") == 1) ? true : false); tr.setGraduacion(cmd.getString("graduacion")); tr.setModoPreparacion(cmd.getString("modopreparacion")); tr.setNombre(cmd.getString("nombre")); tr.setPositivo(cmd.getInt("positivo")); tr.setNegativo(cmd.getInt("negativo")); colTragos.add(tr); } cmd.close(); sql.close(); con.close(); for (Trago tr1 : colTragos) { tr1.setReceta(ADReceta.getInstancia().GetAllByIdTrago(tr1.getId())); } return colTragos; } catch (Exception ex) { throw ex; } }
public void editar(Guia objeto, Usuario usuario, String xml) throws Exception { try { cnn = Conexion.getConexion(); CallableStatement cs = null; cs = cnn.prepareCall("call uspUpdGuia(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); cs.setInt(1, objeto.getIdGuia()); cs.setString(2, objeto.getPeriodo()); cs.setString(3, objeto.getNumero()); cs.setString(4, objeto.getFecha()); cs.setDouble(5, objeto.getTipoCambio()); cs.setString(6, objeto.getSerie()); cs.setString(7, objeto.getNumeroDocumento()); cs.setInt(8, objeto.getIdTipoMovimiento()); cs.setString(9, objeto.getReferencia()); cs.setInt(10, objeto.getIdOrdenProduccion()); cs.setInt(11, objeto.getIdClienteProveedor()); cs.setInt(12, objeto.getIdAlmacen()); cs.setString(13, objeto.getObservaciones()); cs.setString(14, usuario.getNick()); cs.setString(15, xml); cs.execute(); cnn.close(); cs.close(); } catch (SQLException ex) { throw ex; } }
public Guia obtener(int id) throws Exception { Guia objeto = new Guia(); try { cnn = Conexion.getConexion(); CallableStatement cs = null; cs = cnn.prepareCall("call uspGetGuia(?)"); cs.setInt(1, id); rs = cs.executeQuery(); while (rs.next()) { objeto.setIdGuia(rs.getInt("Idguia")); objeto.setPeriodo(rs.getString("Periodo")); objeto.setNumero(rs.getString("Numero")); objeto.setFecha(rs.getString("Fecha")); objeto.setTipoCambio(rs.getDouble("Tipocambio")); objeto.setSerie(rs.getString("Serie")); objeto.setNumeroDocumento(rs.getString("Numerodocumento")); objeto.setIdTipoMovimiento(rs.getInt("Idtipomovimiento")); objeto.setReferencia(rs.getString("Referencia")); objeto.setIdOrdenProduccion(rs.getInt("Idordenproduccion")); objeto.setIdClienteProveedor(rs.getInt("Idclienteproveedor")); objeto.setIdAlmacen(rs.getInt("Idalmacen")); objeto.setObservaciones(rs.getString("Observaciones")); objeto.setDOrdenProduccion(rs.getString("DOrdenProduccion")); objeto.setDClienteProveedor(rs.getString("DClienteProveedor")); } cnn.close(); cs.close(); } catch (SQLException ex) { throw ex; } return objeto; }