Professional Documents
Culture Documents
Para la codificación del sistema de información se dividió el programa en las diferentes etapas
del modelo:
MODELO: en esta fase encontramos la representación de los datos (Base de Datos) que
maneja el sistema, su lógica de negocio, y sus mecanismos de persistencia.
Para la creación de la base de datos del proyecto de formación se selecciono el sistema gestor
de base de datos ORACLE.
Sentencia SQL creación de la tabla Cargo:
Describe cargo;
Sentencia SQL creación de la tabla empleado:
Describe empleado;
Describe usuario;
Sentencia SQL creación de la tabla Proveedor:
Describe proveedor;
CONTROLADOR
package org.pkg.conn;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ConnOracle {
private java.sql.Connection con=null;
private java.sql.Statement stmt;
public ResultSet resultado;
//consulta: sentencia sql. modo: 1->insert, delete, update. 2->select.
public String consultaOrcl(String consulta, Integer modo)
{
String regs ="";
StringWriter sw = null;
PrintWriter pw = null;
try
{
String driver = "oracle.jdbc.OracleDriver";
String ulrjdbc =
"jdbc:oracle:thin:SCOTT/PASSWORD@SERVER_IP:1521:SERVICE_NAME";
Class.forName(driver).newInstance();
con = DriverManager.getConnection(ulrjdbc);
stmt = (Statement) con.createStatement();
//modo=1 -> insert,update,delete; modo=2 -> select
if (modo == 1)
{
stmt.executeUpdate(consulta);
}
else
{
resultado = (ResultSet) stmt.executeQuery(consulta);
}
while (resultado.next())
{
regs = regs + "EMPNO: " + resultado.getString(1) + " ENAME: "+
(resultado.getString(2)) + " JOB: "+ (resultado.getString(3))+"n";
}
try
{
resultado.close();
stmt.close();
con.close();
}
catch (SQLException e )
{
sw = new StringWriter();
pw = new PrintWriter(sw);
e.printStackTrace(pw);
return "rn" + sw.toString() + "rn";
}
}
catch (Exception ex)
{
sw = new StringWriter();
pw = new PrintWriter(sw);
ex.printStackTrace(pw);
return "rn" + sw.toString() + "rn";
}
return regs;
}
}
int dineroEnCaja;
private Producto p1;
private Producto p2;
private Producto p3;
private Producto p4;
public static void main(String[] args) {
Producto p1 = new Producto("Lulo", "SAD", 2.2);
System.out.println(p1.nombre+": "+p1.precio+":
"+p1.codigo);
//Attributes
private String nombre;
private double precioUnit;
private int cantStock;
private boolean disponible = false;
public static int dimesionArray;
//Constructors
public Producto() { }
public Producto(String nombre, double precioUnit, int cantStock, boolean disponible) {
this.nombre = nombre;
this.precioUnit = precioUnit;
this.cantStock = cantStock;
this.disponible = disponible;
dimesionArray++;//Se obtiene con esta variable la dimensión del array. Según número de
instancias del constructor
}
//Methods
@Override
public String toString() {
return "Nombre: " +this.getNombre()+ "\n"+
"Precio unidad: " +this.getPrecioUnit()+ " €\n"+
"En Stock: " +this.getCantStock()+ "\n";
}
INTERFAZ GRÁFICA