Sunteți pe pagina 1din 9

Conexion importjava.sql.

*;

String modi2=""; String prcl2="";

Conexion(String prcl0)//consultardatos { prclok=prcl0;

public class Conexion { Object[][] data = null;

int flag2,hora2,minuto2,segundo2,fac,tot ;

VerificaDriver();

VerificaOdbc_2(); Connection con; Statement stat; ResultSetrs; int j; String pr3[]=new String[100]; VerificaSql_9();} String prcl3[]=new String[100]; int hora4[]=new int[100]; int minuto4[]=new int[100]; int segundo4[]=new int[100]; int cod1[]=new int[100]; Object[][] datas = null; String pr1[]=new String[100]; String fm1[]=new String[100]; { String des1[]=new String[100]; fac=flag; int stock1[]=new int[100]; VerificaDriver(); int prec1[]=new int[100]; VerificaOdbc(); VerificaSql_3(); } if(fac==0) String cod2[]=new String[100]; {VerificaSql();} String nom2[]=new String[100]; String ap2[]=new String[100]; if(fac==1) String am2[]=new String[100]; {VerificaSql_8();} String direc2[]=new String[100]; } String edad2[]=new String[100]; String ulcom2[]=new String[100]; Conexion(intcod,int flag)//consultardatos { tot=flag; String prclok=""; intcodigook; String prok=""; precok=prec; String fmok=""; String desok=""; intstockok; VerificaSql_2(); } intprecok; VerificaOdbc(); VerificaDriver(); VerificaSql_1();} VerificaOdbc(); codigook=cod; { codigook=cod; VerificaDriver(); stockok=stock; } Conexion(intcod,intstock,intprec)//m odificar los datos del producto VerificaSql_4();} VerificaOdbc(); if(flag2==2) { VerificaDriver(); VerificaOdbc(); {VerificaDriver(); if(flag2==1) Conexion(int flag)//copiardatos a unatabla Conexion(intcod,Stringpr,Stringfm,Str ingdes,intstock,intprec,int flag1) { codigook=cod; prok=pr; fmok=fm; desok=des; stockok=stock; precok=prec; flag2=flag1;

Conexion(String modi,String prcl0,int cod,intap,int am)//hora { hora2=cod;

{ con = DriverManager.getConnection("jdbc: odbc:Database2", "", ""); System.out.println("ok..........ODBC"); }catch(Exception e1)

rs=stat.executeQuery("Select * from Datos2"); System.out.println("ok..........SQL");j= 0; while(rs.next()) {cod2[j]=rs.getString("id_cliente");

minuto2=ap; segundo2=am; modi2=modi; } prcl2=prcl0; am2[j]=rs.getString("am"); VerificaDriver(); ///////////// sql VerificaOdbc_2(); void VerificaSql() VerificaSql_5();} {try /////////////// driver void VerificaDriver() {try {Class.forName("sun.jdbc.odbc.JdbcO dbcDriver"); System.out.println("ok..........DRIVER" );} catch(Exception e1) {cod1[j]=rs.getInt("id_producto"); {System.out.println("ERROR.........DRI VER NO EXISTE");} } /////////////// ODBC void VerificaOdbc() { try { con = DriverManager.getConnection("jdbc: odbc:Database", "", ""); System.out.println("ok..........ODBC"); }catch(Exception e1) } minuto4[j]=rs.getInt("minuto"); {System.out.println("ERROR..........OD BC NO EXISTE");} } void VerificaOdbc_2() { try stat = con.createStatement(ResultSet.TYPE_ SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); con.close(); stat.close();} void VerificaSql_8() {try{ segundo4[j]=rs.getInt("segundo");j++; } {try{ pr1[j]=rs.getString("producto"); fm1[j]=rs.getString("familia"); des1[j]=rs.getString("descripcion"); stock1[j]=rs.getInt("stock"); prec1[j]=rs.getInt("precio"); System.out.println("ojo..."+cod1[j]); j++; } } catch(Exception e1) {System.out.println("ERROR..........SQL NO EXISTE");} System.out.println("ok..........SQL");j= 0; while(rs.next()) {pr3[j]=rs.getString("Proceso"); prcl3[j]=rs.getString("Producto"); hora4[j]=rs.getInt("hora"); stat = con.createStatement(ResultSet.TYPE_ SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); rs=stat.executeQuery("Select * from Hora2 where Proceso='"+prclok+"'"); {stat = con.createStatement(ResultSet.TYPE_ SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); rs=stat.executeQuery("Select * from Datos"); System.out.println("ok..........SQL"); } while(rs.next()) void VerificaSql_9()//hora con.close(); stat.close();} catch(Exception e1) {System.out.println("ERROR..........SQL NO EXISTE");} ulcom2[j]=rs.getString("ulcom");j++;} edad2[j]=rs.getString("edad"); direc2[j]=rs.getString("direc"); ap2[j]=rs.getString("ap"); {System.out.println("ERROR..........OD BC NO EXISTE");}

nom2[j]=rs.getString("nombre");

catch(Exception e1) {System.out.println("ERROR..........SQL NO EXISTE");} } //////////////// verificacodigo void VerificaSql_1() {try{

SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); stat.execute("Update Datos Set stock="+stockok+",precio="+precok+" where id_producto="+codigook+" "); System.out.println("wwwww1"); System.out.println("ok.........procedio la modificacion"); con.close();

System.out.println("ok.........procedio la modificacion"); con.close(); stat.close(); }catch(Exception e1) {System.out.println("ERROR..........no modifica");} } void VerificaSql_5() {try{ stat = con.createStatement(ResultSet.TYPE_ SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); stat.execute("INSERT INTO Hora2 (Proceso, Producto, hora, minuto, segundo) VALUES " + "('"+modi2+"','"+ prcl2+"',"+hora2+","+minuto2+","+se gundo2+" )"); System.out.println("wwwww1");

stat = con.createStatement(ResultSet.TYPE_ SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); rs=stat.executeQuery("Select * from Datos where id_producto="+codigook+" "); System.out.println("ok..........SQL");j= 0; if(rs.next()) {cod1[j]=rs.getInt("id_producto"); pr1[j]=rs.getString("producto"); des1[j]=rs.getString("descripcion"); fm1[j]=rs.getString("familia"); stock1[j]=rs.getInt("stock"); prec1[j]=rs.getInt("precio");j++; System.out.println("r...codigoexiste"); con.close(); stat.close();} else { System.out.println("error...codigo no existe");} }catch(Exception e1) {System.out.println("ERROR..........SQL NO EXISTE");} } ////// verificacodigo void VerificaSql_2() {try{ stat = con.createStatement(ResultSet.TYPE_

stat.close(); } catch(Exception e1) {System.out.println("ERROR..........no modifica");} } void VerificaSql_3() {try {stat = con.createStatement(ResultSet.TYPE_ SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); stat.execute("DELETE FROM Datos where id_producto="+codigook+" "); System.out.println("wwwww1");

System.out.println("ok.........procedio la modificacion"); con.close();stat.close();}

System.out.println("ok.........procedio la eliminacion"); con.close();stat.close();} catch(Exception e1)

catch(Exception e1) {System.out.println("ERROR..........no modifica");} }}// clase

{System.out.println("ERROR..........no elimina");} } void VerificaSql_4() {try{ stat = con.createStatement(ResultSet.TYPE_ SCROLL_SENSITIVE,ResultSet.CONCU R_UPDATABLE ); stat.execute("INSERT INTO Datos (id_producto, producto, familia, descripcion, stock, precio) VALUES ('"+codigook+"','"+prok+"','"+fmok+"', '"+desok+"','"+stockok+"','"+precok+" ' )"); System.out.println("wwwww1");

Eliminacin

importjava.lang.Object; /* * Cliente_Modificacion2.java

System.out.println("ojo..."+dato.j); Object [][]data = new Object[(dato.j)+1][4]; for(int m=0;m<dato.j;m++)

*/ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

* { * Created on 12/06/2011, 06:34:50 PM */ importjava.awt.Font; importjavax.swing.table.DefaultTable Model; data[m][0]= dato.prcl3[m]; data[m][1]= dato.hora3[m]; data[m][2]= dato.minuto3[m]; data[m][3]= dato.segundo3[m];

jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable();

importjavax.swing.ListSelectionModel ; importjavax.swing.JOptionPane; importjava.awt.Font;

System.out.println("ojo..."+data[m][1 ]); }

setDefaultCloseOperation(javax.swin g.WindowConstants.EXIT_ON_CLOSE) ; String[] columnNames = {"Codigo",

/** "hora", * "minuto", * @author JULIO "segundo"}; */ {null, null, null, null}, public class Eliminar_proceso extends javax.swing.JFrame { String prcl="Eliminar"; /** Creates new form Eliminar_proceso */ }, publicEliminar_proceso() { jTable1.setModel(dtm); initComponents(); "Title 1", "Title 2", "Title 3", setLocation(150,50); // setSize(400,300); } setTitle("Modulo de consulta"); )); jScrollPane1.setViewportView(jTable 1); "Title 4" } new String [] { DefaultTableModeldtm= new DefaultTableModel(data, columnNames);//tabla dinamica {null, null, null, null}, {null, null, null, null}, {null, null, null, null} new Object [][] { jTable1.setModel(new javax.swing.table.DefaultTableModel(

/** This method is called from within the constructor to // for(int k=0;k<dato.j;k++8 * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor.

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(

Conexiondato=new Conexion(prcl);

jPanel1Layout.createParallelGroup(ja vax.swing.GroupLayout.Alignment.LE ADING)

public void run() { .addGroup(layout.createSequentialGr oup() .addContainerGap() newEliminar_proceso().setVisible(tru e); } .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED _SIZE, javax.swing.GroupLayout.DEFAULT_SI ZE, javax.swing.GroupLayout.PREFERRED _SIZE) }); }

.addGroup(javax.swing.GroupLayout. Alignment.TRAILING, jPanel1Layout.createSequentialGroup ()

.addContainerGap(javax.swing.Group Layout.DEFAULT_SIZE, Short.MAX_VALUE)

// Variables declaration - do not modify .addContainerGap(javax.swing.Group Layout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( privatejavax.swing.JPanel jPanel1; privatejavax.swing.JScrollPane jScrollPane1; privatejavax.swing.JTable jTable1; // End of variables declaration

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED _SIZE, 375, javax.swing.GroupLayout.PREFERRED _SIZE) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(ja vax.swing.GroupLayout.Alignment.LE ADING)

layout.createParallelGroup(javax.swin g.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGr oup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED _SIZE, javax.swing.GroupLayout.DEFAULT_SI ZE, javax.swing.GroupLayout.PREFERRED _SIZE)

.addGroup(javax.swing.GroupLayout. Alignment.TRAILING, jPanel1Layout.createSequentialGroup () .addContainerGap(22, Short.MAX_VALUE)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED _SIZE, 130, javax.swing.GroupLayout.PREFERRED _SIZE) .addGap(145, 145, 145))

.addContainerGap(javax.swing.Group Layout.DEFAULT_SIZE, Short.MAX_VALUE)) ); Modificacin pack(); importjava.awt.Font; /** *

); }// </editor-fold>

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContent Pane()); getContentPane().setLayout(layout);

/** * @paramargs the command line arguments */

* @author Administrador */ publicclassCliente_Modificacionexten dsjavax.swing.JFrame { private Hora hora;

layout.setHorizontalGroup( public static void main(String args[]) { layout.createParallelGroup(javax.swin g.GroupLayout.Alignment.LEADING) java.awt.EventQueue.invokeLater(ne w Runnable() {

/** Creates new formCliente_Modificacion */

jTable1.setValueAt(dato.prec1[k], k,5);

Consulta = new javax.swing.JMenuItem(); Procesos = new javax.swing.JMenu();

Stringcodigo=""; } jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); } String apw=""; String amw=""; /** This method is called from within the constructor to String cadw[]=new String[50]; /** Creates new form Cliente_Modificacion2 */ public Cliente_Modificacion() { initComponents(); */ setLocation(150,50); @SuppressWarnings("unchecked") // setSize(400,300); setTitle("Modulo de consulta"); // <editor-fold defaultstate="collapsed" desc="Generated Code"> } private void initComponents() { flag=0; Conexion dato=new Conexion(flag); }); public void windowOpened(java.awt.event.Wind owEvent evt) { formWindowOpened(evt); * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. setDefaultCloseOperation(javax.swin g.WindowConstants.EXIT_ON_CLOSE) ; addWindowListener(new java.awt.event.WindowAdapter() { jMenuItem3 = new javax.swing.JMenuItem(); CerrarSesion = new javax.swing.JMenu();

int flag; String codw="";

jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jMenuBar1 = new javax.swing.JMenuBar(); Productos = new javax.swing.JMenu(); Modificar = new javax.swing.JMenuItem(); Insertar = new javax.swing.JMenuItem(); Eliminar = new javax.swing.JMenuItem(); Clientes = new javax.swing.JMenu();

System.out.println("ojo..."+dato.j); // for(int k=0;k<dato.j;k++)

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

for(int k=0;k<4;k++) { jTable1.setValueAt(dato.cod1[k], k, 0); jTable1.setValueAt(dato.pr1[k], k, 1); jTable1.setValueAt(dato.des1[k], k, 2); jTable1.setValueAt(dato.fm1[k], k,3);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(ja vax.swing.GroupLayout.Alignment.LE ADING) .addGap(0, 14, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup(

jTable1.setValueAt(dato.stock1[k], k,4);

jPanel1Layout.createParallelGroup(ja vax.swing.GroupLayout.Alignment.LE ADING)

.addGap(0, 146, Short.MAX_VALUE) );

jTable1.getColumnModel().getColum n(3).setHeaderValue("Descripcion");

EliminarActionPerformed(evt); }

jTable1.getColumnModel().getColum n(4).setHeaderValue("Stock"); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null, null, null}, Productos.setText("Productos"); {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, {null, null, null, null, null, null}, }); {null, null, null, null, null, null}, {null, null, null, null, null, null} Insertar.setText("Insertar"); }, new String [] { "Codigo", "Producto", "Familia", "Descripcion", "Stock", "Precio" } InsertarActionPerformed(evt); )); } jScrollPane1.setViewportView(jTable 1); }); Productos.add(Insertar); Insertar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.Acti onEvent evt) { Productos.add(Modificar); ModificarActionPerformed(evt); public void actionPerformed(java.awt.event.Acti onEvent evt) { Modificar.addActionListener(new java.awt.event.ActionListener() { Modificar.setText("Modificar"); jTable1.getColumnModel().getColum n(5).setHeaderValue("Precio");

}); Productos.add(Eliminar);

jMenuBar1.add(Productos);

Clientes.setText("Clientes");

Consulta.setText("Consulta"); Consulta.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.Acti onEvent evt) {

ConsultaActionPerformed(evt); } } }); Clientes.add(Consulta);

jMenuBar1.add(Clientes);

Procesos.setText("Procesos");

jMenuItem1.setText("Eliminacion"); Procesos.add(jMenuItem1);

jMenuItem2.setText("Modificacion"); jTable1.getColumnModel().getColum n(0).setHeaderValue("Codigo"); Eliminar.setText("Eliminar"); jTable1.getColumnModel().getColum n(1).setHeaderValue("Producto"); Eliminar.addActionListener(new java.awt.event.ActionListener() { jMenuItem3.setText("Insercion"); jTable1.getColumnModel().getColum n(2).setHeaderValue("Familia"); public void actionPerformed(java.awt.event.Acti onEvent evt) { Procesos.add(jMenuItem2);

); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.Acti onEvent evt) { .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED _SIZE, javax.swing.GroupLayout.DEFAULT_SI ZE, javax.swing.GroupLayout.PREFERRED _SIZE)

pack(); }// </editor-fold>

jMenuItem3ActionPerformed(evt); } }); Procesos.add(jMenuItem3); .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SI ZE, javax.swing.GroupLayout.DEFAULT_SI ZE, Short.MAX_VALUE) .addContainerGap()) ); CerrarSesion.setText("Cerrar sesin"); layout.setVerticalGroup( CerrarSesion.addMouseListener(new java.awt.event.MouseAdapter() { publicvoidmouseClicked(java.awt.eve nt.MouseEventevt) { CerrarSesionMouseClicked(evt); } .addContainerGap() }); jMenuBar1.add(CerrarSesion); .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED _SIZE, javax.swing.GroupLayout.DEFAULT_SI ZE, javax.swing.GroupLayout.PREFERRED _SIZE) layout.createParallelGroup(javax.swin g.GroupLayout.Alignment.LEADING) hora.setFont(new Font("Trebuchet MS",java.awt.Font.BOLD, 20));/*Cambiamos la fuente, estilo y tamao*/ this.add(hora); // TODO add your handling code here: } .addGroup(layout.createSequentialGr oup() private void ModificarActionPerformed(java.awt.e vent.ActionEvent evt) { setVisible(false); Modificar xx3=new Modificar(); xx3.setVisible(true); // TODO add your handling code here: } javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContent Pane()); .addContainerGap(javax.swing.Group Layout.DEFAULT_SIZE, Short.MAX_VALUE)) private void InsertarActionPerformed(java.awt.ev ent.ActionEvent evt) { setVisible(false); Insertar xx6=new Insertar(); xx6.setVisible(true); // TODO add your handling code here: .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED _SIZE, 114, javax.swing.GroupLayout.PREFERRED _SIZE) .addGap(25, 25, 25)) } hora = new Hora();/***Inicializar la variable hora***/ hora.setBounds(350, 5, 240, 30);/*(Ubicacion en eje x, Ubicacion en eje y, Ancho, Alto)*/ .addPreferredGap(javax.swing.Layout Style.ComponentPlacement.RELATED ) private void formWindowOpened(java.awt.event. WindowEvent evt) {

jMenuBar1.add(Procesos);

setJMenuBar(jMenuBar1);

getContentPane().setLayout(layout); layout.setHorizontalGroup(

.addGroup(javax.swing.GroupLayout. Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(29, Short.MAX_VALUE)

layout.createParallelGroup(javax.swin g.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGr oup() .addContainerGap()

private void EliminarActionPerformed(java.awt.ev ent.ActionEvent evt) {

setVisible(false); Eliminar xx5=new Eliminar(); xx5.setVisible(true); // TODO add your handling code here: } java.awt.EventQueue.invokeLater(ne w Runnable() { public void run() { new Cliente_Modificacion().setVisible(true ); } private void ConsultaActionPerformed(java.awt.e vent.ActionEvent evt) { } setVisible(false); ConsultaCliente xx6=new ConsultaCliente(); xx6.setVisible(true); // TODO add your handling code here: } private javax.swing.JMenu Clientes; private javax.swing.JMenuItem Consulta; private javax.swing.JMenuItem Eliminar; private javax.swing.JMenuItem Insertar; private javax.swing.JMenuItem Modificar; privatejavax.swing.JMenu Procesos; privatejavax.swing.JMenu Productos; private void jMenuItem3ActionPerformed(java.aw t.event.ActionEvent evt) { // TODO add your handling code here: } private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; /** private javax.swing.JPanel jPanel1; * @param args the command line arguments */ privatejavax.swing.JTable jTable1; public static void main(String args[]) { private javax.swing.JScrollPane jScrollPane1; });

// Variables declaration - do not modify private javax.swing.JMenu CerrarSesion;

private void CerrarSesionMouseClicked(java.awt.e vent.MouseEvent evt) { setVisible(false); Inicio xx3=new Inicio(); xx3.setVisible(true); // TODO add your handling code here: }

S-ar putea să vă placă și