Clase Persona:
Código
import java.sql.SQLException; /* * * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author ramondevesa */ public class Persona { String Nombre, Telefono, Sexo, Foto; public void Persona() throws Class.forName(controlador).newInstance(); conectar(); crearSentencia(); } URL_bd, usuario, contraseña); } sentenciaSQL = conexion.createStatement(); } if(cdr != null) cdr.close(); if(sentenciaSQL != null) sentenciaSQL.close(); if(conexion != null) conexion.close(); } cdr = sentenciaSQL.executeQuery(sql); Persona persona01 = new Persona(); return cdr; } { Nombre=nombre_; Telefono = telefono_; Sexo = sexo_; Foto = foto_; } /*public void guardar(String nombre_, String telefono_, String sexo_, String foto_) throws java.sql.SQLException{ String sql = "INSNERT INTO personas ('"+nombre_+"', '"+telefono_+"', '"+sexo_+"', "+foto_+"')"; cdr = sentenciaSQL.executeQuery(sql); }*/ public void guardar(String nombre_, String telefono_, String sexo_, String foto_) throws java.sql.SQLException{ cdr = sentenciaSQL.executeQuery(sql); } }
Clase JFrame:
Código
import javax.swing.*; /* * IGPersona.java * * Created on 01-jun-2012, 23:31:09 */ /** * * @author ramondevesa */ private static Persona BD; /** Creates new form IGPersona */ public IGPersona() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { label_nombre.setText("Nombre:"); txtNombreActionPerformed(evt); } }); label_telefono.setText("Teléfono:"); label_sexo.setText("Sexo:"); buttonGroup1.add(GHombre); GHombre.setText("Hombre"); buttonGroup1.add(GMujer); GMujer.setText("Mujer"); btnExaminar.setText("Examinar"); org.jdesktop.layout.GroupLayout pImagenLayout = new org.jdesktop.layout.GroupLayout(pImagen); pImagen.setLayout(pImagenLayout); pImagenLayout.setHorizontalGroup( pImagenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) ); pImagenLayout.setVerticalGroup( pImagenLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) ); btnVaciar.setText("Vaciar"); btnGuardar.setText("Guardar"); jScrollPane1.setViewportView(jList1); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(label_nombre) .add(label_telefono) .add(label_sexo)) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtTelefono, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 247, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(layout.createSequentialGroup() .add(GHombre) .add(18, 18, 18) .add(GMujer) .add(98, 98, 98)) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() .add(btnVaciar) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(btnGuardar)) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() .add(btnExaminar) .add(18, 18, 18) .add(pImagen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) .add(27, 27, 27))) .add(18, 18, 18) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 271, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); layout.linkSize(new java.awt.Component[] {txtNombre, txtTelefono}, org.jdesktop.layout.GroupLayout.HORIZONTAL); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap()) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(label_nombre) .add(txtNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(label_telefono) .add(txtTelefono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(label_sexo) .add(GHombre) .add(GMujer)) .add(30, 30, 30) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(btnExaminar) .add(pImagen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnVaciar) .add(btnGuardar)) .add(92, 92, 92)))) ); pack(); }// </editor-fold> // TODO add your handling code here: } /** * @param args the command line arguments */ /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { break; } } java.util.logging.Logger.getLogger(IGPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(IGPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(IGPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(IGPersona.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ public void run() { new IGPersona().setVisible(true); } }); } // Variables declaration - do not modify // End of variables declaration }