Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CLASE JUEGO
- package Modelo;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Juego {
- Conectar c;
- public Juego() {
- c = new Conectar();
- }
- public int agregar(int id, int stock, String nombre, String precio, String categoria){
- try{
- Statement agregar=c.crearSentencia();
- return agregar.executeUpdate("insert into juego (ID,Stock,Nombre,Categoria,Precio) values ("+id+","+stock+",'"+nombre+"','"+precio+"','"+categoria+"')");
- }catch(SQLException ex){
- return -1;
- }
- }
- public int modificarPrecio(int id, String nuevoPrecio){
- try{
- Statement s=c.crearSentencia();
- return s.executeUpdate("UPDATE juego SET precio='"+nuevoPrecio+"'WHERE id='"+id+"'");
- }catch(SQLException ex){
- return -1;
- }
- }
- }
- //CLASE TIENDA
- package Modelo;
- import java.util.ArrayList;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.swing.table.DefaultTableModel;
- public class Tienda {
- Conectar c;
- public ArrayList <Juego> lista = new ArrayList();
- public ArrayList<Juego> getLista() {
- return lista;
- }
- public void setLista(ArrayList<Juego> lista) {
- this.lista = lista;
- }
- public Tienda() {
- c = new Conectar();
- }
- public int cliente(int rut, int telefono, String nombre, String direccion, String ciudad){
- try{
- Statement agregar=c.crearSentencia();
- return agregar.executeUpdate("insert into cliente (Rut,Telefono,Nombre,Direccion,Ciudad) values ("+rut+","+telefono+",'"+nombre+"','"+direccion+"','"+ciudad+"')");
- }catch(SQLException ex){
- return -1;
- }
- }
- public int venta (int id, String valor, int cantidad){
- try{
- Statement s=c.crearSentencia();
- return s.executeUpdate("insert into venta (ID_juego,Valor_total,Cantidad) values ("+id+",'"+valor+"','"+cantidad+"')");
- }catch(SQLException ex){
- return -1;
- }
- }
- public int ventaResta (int id, int nuevoStock){
- try{
- Statement s=c.crearSentencia();
- return s.executeUpdate("UPDATE juego SET stock=stock - "+nuevoStock+" WHERE ID="+id+"");
- }catch(SQLException ex){
- return -1;
- }
- }
- }
- //CLASE CONECTAR
- package Modelo;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Conectar {
- private Connection conn;
- private String registrar(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- return "Exito";
- }catch(ClassNotFoundException e){
- return "no registrado";
- }
- }
- private String obtenerConexion(){
- try{
- conn=DriverManager.getConnection("jdbc:mysql://localhost/prueba","root","");
- return "Exito";
- }catch (SQLException e){
- return "no conectado";
- }
- }
- public Statement crearSentencia(){
- try{
- Statement s = conn.createStatement();
- return s;
- }catch(SQLException e){
- return null;
- }
- }
- public Conectar() {
- registrar();
- obtenerConexion();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement