Professional Documents
Culture Documents
conexion;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* Constructor privado aplicando patron Singleton
*/
private Conexion() {
configurar();
}
/**
* Metodo para retorna una instancia de la conexion. Si no esta creada la
* crea, y si esta creada la retorna
*
* @return retorna una instancia de la conexin a la base de datos
*/
public synchronized static Conexion crearInstancia() {
if (instancia == null) {
instancia = new Conexion();
}
return instancia;
}
/**
* Metodo para obtener la conexion
*
* @return retorna el objeto de la conexion
*/
public Connection getConexion() {
return con;
}
/**
* Metodo para establecer los puertos, base de datos y demas informacion
* para la conexion con el SGBD
*/
private void configurar() {
String cadena_conexion_sql = "jdbc:mysql://localhost:3306/modulo_venta";
String urlusuario = "root";
String urlcontrasea = "";
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(cadena_conexion_sql, urlusuario, urlcontrasea);
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Error :" + e.getMessage());
}
}
/**
* Metodo para hacer una consulta usando un procedimiento almacenado
*
* @param sql
* @return
* @throws Exception
*/
public ResultSet consultar(String sql) throws Exception {
try {
Statement st = con.createStatement();
ResultSet resultado = st.executeQuery(sql);
return resultado;
} catch (Exception e) {
throw new Exception("Error al consultar la BD " + e.getMessage());
}
}
/**
* Metodo para preparar llamada de un procedimiento almacenado con parametro
* de salida
*
* @param proc: String que contiene el nombre de la consulta del proc. alm
* @return: retorna un objeto del tipo callablestatement
*/
public CallableStatement ejecutar_Proc_Almacenado(String proc) throws Exception {
try {
CallableStatement cst = con.prepareCall(proc);
return cst;
} catch (Exception e) {
throw new Exception("Error al consultar la BD " + e.getMessage());
}
}
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextArea;
import org.unp.generador.conexion.Conexion;
import org.unp.generador.entidad.Detalle_boleta;
public void generar_boletas(int anio, int mes, int boletasxdia, int cantidad_detalles, JTextArea a)
throws SQLException {
int nboletas = 0;
int ndetalles = 0;
switch (boletasxdia) {
case 0:
nboletas = 2000;
break;
case 1:
nboletas = 3000;
break;
case 2:
nboletas = 4000;
break;
}
switch (cantidad_detalles) {
case 0:
ndetalles = 30;
break;
case 1:
ndetalles = 40;
break;
case 2:
ndetalles = 50;
break;
}
if (band) {
int cant = (int) (Math.random() * 10 + 1);
double precio = buscar_producto(codigop);
double monto_parcial = cant * precio;
/**
*
* @param anio ao de la fecha
* @param mes mes seleccionado
* @return cantidad de dias para el ao y mes especificados como parametro
*/
public int obtener_cantidad_dias_mes(int anio, int mes) {
Calendar cal = new GregorianCalendar(anio, mes, 1);
return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
}
}
/*
Navicat MySQL Data Transfer
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for boleta
-- ----------------------------
DROP TABLE IF EXISTS `boleta`;
CREATE TABLE `boleta` (
`cod_boleta` int(11) NOT NULL AUTO_INCREMENT,
`id_cliente` int(11) DEFAULT NULL,
`id_usuario` int(11) DEFAULT NULL,
`fecha` date DEFAULT NULL,
`total` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`cod_boleta`),
KEY `id_cliente` (`id_cliente`),
KEY `id_usuario` (`id_usuario`),
CONSTRAINT `boleta_ibfk_1` FOREIGN KEY (`id_cliente`) REFERENCES `cliente` (`id_cliente`),
CONSTRAINT `boleta_ibfk_2` FOREIGN KEY (`id_usuario`) REFERENCES `usuario` (`id_usuario`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of boleta
-- ----------------------------
-- ----------------------------
-- Table structure for categoria
-- ----------------------------
DROP TABLE IF EXISTS `categoria`;
CREATE TABLE `categoria` (
`cod_categoria` int(11) NOT NULL AUTO_INCREMENT,
`Nombre` varchar(40) DEFAULT NULL,
`Descripcione` varchar(40) DEFAULT NULL,
PRIMARY KEY (`cod_categoria`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of categoria
-- ----------------------------
-- ----------------------------
-- Table structure for cliente
-- ----------------------------
DROP TABLE IF EXISTS `cliente`;
CREATE TABLE `cliente` (
`id_cliente` int(11) NOT NULL AUTO_INCREMENT,
`nombres` varchar(80) DEFAULT NULL,
`apellidos` varchar(80) DEFAULT NULL,
`direccion` varchar(100) DEFAULT NULL,
`fecha_ingreso` date DEFAULT NULL,
PRIMARY KEY (`id_cliente`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of cliente
-- ----------------------------
-- ----------------------------
-- Table structure for detalle_boleta
-- ----------------------------
DROP TABLE IF EXISTS `detalle_boleta`;
CREATE TABLE `detalle_boleta` (
`id_detalle` int(11) NOT NULL AUTO_INCREMENT,
`cod_boleta` int(11) DEFAULT NULL,
`cod_producto` int(11) DEFAULT NULL,
`cantidad` smallint(6) DEFAULT NULL,
`precio` decimal(10,2) DEFAULT NULL,
`monto_parcial` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`id_detalle`),
KEY `cod_boleta` (`cod_boleta`),
KEY `cod_producto` (`cod_producto`),
CONSTRAINT `detalle_boleta_ibfk_1` FOREIGN KEY (`cod_boleta`) REFERENCES `boleta`
(`cod_boleta`),
CONSTRAINT `detalle_boleta_ibfk_2` FOREIGN KEY (`cod_producto`) REFERENCES `producto`
(`cod_producto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of detalle_boleta
-- ----------------------------
-- ----------------------------
-- Table structure for producto
-- ----------------------------
DROP TABLE IF EXISTS `producto`;
CREATE TABLE `producto` (
`cod_producto` int(11) NOT NULL AUTO_INCREMENT,
`cod_categoria` int(11) DEFAULT NULL,
`nombre` varchar(80) DEFAULT NULL,
`precio` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`cod_producto`),
KEY `cod_categoria` (`cod_categoria`),
CONSTRAINT `producto_ibfk_1` FOREIGN KEY (`cod_categoria`) REFERENCES `categoria`
(`cod_categoria`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of producto
-- ----------------------------
-- ----------------------------
-- Table structure for usuario
-- ----------------------------
DROP TABLE IF EXISTS `usuario`;
CREATE TABLE `usuario` (
`id_usuario` int(11) NOT NULL AUTO_INCREMENT,
`tipo_usuario` smallint(6) DEFAULT NULL,
`username` char(50) DEFAULT NULL,
`pass` char(50) DEFAULT NULL,
PRIMARY KEY (`id_usuario`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of usuario
-- ----------------------------