Nada. Ahi va el codigo completo:
import java.awt.Choice;
import java.awt.Label;
import java.io.File;
import java.lang.String;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on 28/11/2011, 02:02:16 PM
*/
/**
*
* @author bladimir
*/
public final class Inicio extends javax.swing.JFrame {
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private java.awt.Choice choice1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private java.awt.Panel panel1;
private java.awt.Panel panel10;
private java.awt.Panel panel2;
private java.awt.Panel panel3;
private java.awt.Panel panel4;
private java.awt.Panel panel5;
private java.awt.Panel panel6;
private java.awt.Panel panel7;
private java.awt.Panel panel8;
private java.awt.Panel panel9;
int r = 0;
/** Creates new form NewJFrame */
public Inicio() {
try {
initComponents();
creardirectorio();
creartablas();
cargarlista();
} catch (SQLException ex) {
Logger.getLogger(Inicio.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void creartablas() {
// TODO Auto-generated method stub
Connection conn = null;
Statement st = null;
String sql = null;
try {
Class.forName("org.hsqldb.jdbcDriver" );
} catch (Exception e) {
System.out.println("ERROR: failed to load HSQLDB JDBC driver.");
e.printStackTrace();
return;
}
try
{ // Create tables
conn = DriverManager.getConnection("jdbc:hsqldb:file:/home/bladimir/Pacientes/Pacientes", "bladimir", "2704");
st = conn.createStatement();
sql = "CREATE TABLE pacientes ( " +
"id INTEGER IDENTITY NOT NULL PRIMARY KEY, " +
"nombre VARCHAR(25) NOT NULL, " +
"ci VARCHAR(10), " +
"fechanac VARCHAR(100), " +
"ingreso VARCHAR(100), " +
"ultima VARCHAR(100), " +
"proxima VARCHAR(100), " +
"CONSTRAINT UNIQUE_STU UNIQUE(ci)" +
");";
st.executeUpdate(sql);
System.out.println("* Creando tabla pacientes...");
sql = "CREATE TABLE subject ( " +
"id INTEGER NOT NULL PRIMARY KEY, " +
"name VARCHAR(100) NOT NULL, " +
"CONSTRAINT UNIQUE_SUB UNIQUE(name)" +
");";
st.executeUpdate(sql);
System.out.println("* Creating subject table...");
}
catch (Exception e)
{
System.err.println("Warning: CREATE TABLE: " + e.getMessage());
}
}
private void creardirectorio() {
// TODO Auto-generated method stub
File directorio = new File("/home/bladimir/Pacientes");
if (directorio.mkdir())
System.out.println("Se ha creado directorio");
else
System.out.println("No se ha podido crear el directorio");
}
/** 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">//GEN-BEGIN:initComponents
private void initComponents() throws SQLException{
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
JTabbedPane pestaña = new JTabbedPane();
JPanel panel = new JPanel(null);
pestaña.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
pestaña.setSize(720, 650);
pestaña.setLocation(290, 10);
panel.setBorder(BorderFactory.createTitledBorder("Panel 1"));
Label label1 = new Label();
label1.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
label1.setText("Nombre:");
label1.setBounds(20,30,200,20);
panel.add(label1);
jTextField1.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jTextField1.setText("");
jTextField1.setEditable(false);
jTextField1.setBounds(280,30,420,30);
panel.add(jTextField1);
Label label2 = new Label();
label2.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
label2.setText("CI:");
label2.setBounds(20,70,200,20);
panel.add(label2);
jTextField2.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jTextField2.setText("");
jTextField2.setBounds(280,70,150,30);
jTextField2.setEditable(false);
panel.add(jTextField2);
Label label3 = new Label();
label3.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
label3.setText("Edad:");
label3.setBounds(20,110,200,20);
panel.add(label3);
jTextField3.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jTextField3.setText("");
jTextField3.setBounds(280,110,50,30);
jTextField3.setEditable(false);
panel.add(jTextField3);
Label label4 = new Label();
label4.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
label4.setText("Fecha de ingreso:");
label4.setBounds(20,150,250,30);
panel.add(label4);
jTextField4.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jTextField4.setText("");
jTextField4.setBounds(280,150,150,30);
jTextField4.setEditable(false);
panel.add(jTextField4);
Label label5 = new Label();
label5.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
label5.setText("Ultima Consulta:");
label5.setBounds(20,190,250,30);
panel.add(label5);
jTextField5.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jTextField5.setText("");
jTextField5.setBounds(280,190,150,30);
jTextField5.setEditable(false);
panel.add(jTextField5);
Label label6 = new Label();
label6.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
label6.setText("Proxima Consulta:");
label6.setBounds(20,230,250,30);
panel.add(label6);
JTextField jTextField6 = new JTextField();
jTextField6.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jTextField6.setText("");
jTextField6.setBounds(280,230,150,30);
jTextField6.setEditable(false);
panel.add(jTextField6);
jButton1.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jButton1.setText("Nuevo Paciente");
jButton1.setBounds(50,300,230,30);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
try {
jButton1ActionPerformed(evt);
} catch (Exception ex){
return;
}
}
});
panel.add(jButton1);
jButton2.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jButton2.setText("Editar Paciente");
jButton2.setBounds(420,300,230,30);
panel.add(jButton2);
jButton3.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jButton3.setText("Guardar Paciente");
jButton3.setEnabled(false);
jButton3.setBounds(50,400,230,30);
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
try {
jButton3ActionPerformed(evt);
} catch (Exception ex){
return;
}
}
});
panel.add(jButton3);
jButton4.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jButton4.setText("Eliminar Paciente");
jButton4.setBounds(420,400,230,30);
panel.add(jButton4);
jButton5.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
jButton5.setText("Cancelar");
jButton5.setEnabled(false);
jButton5.setBounds(280,350,140,30);
panel.add(jButton5);
pestaña.addTab("Datos del paciente", panel);
JPanel panel1 = new JPanel();
panel1.setBorder(BorderFactory.createTitledBorder("Panel 2"));
pestaña.addTab("Evaluacion clinica", panel1);
getContentPane().add(pestaña);
JComboBox choice1 = new JComboBox();
choice1.setModel(new DefaultComboBoxModel(new String[] {}));
choice1 = new JComboBox();
choice1.setSize(250, 30);
choice1.setLocation(10, 300);
add(choice1);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1100, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1000, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) throws SQLException {
jButton3.setEnabled(true);
jTextField1.setEditable(true);
jTextField2.setEditable(true);
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jTextField5.setEditable(true);
jTextField6.setEditable(true);
conocernumeroreg();
fechahoy();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) throws SQLException {
guardar();
}
public void guardar(){
Connection conn = null;
Statement st = null;
String sql = null;
ResultSet rst1 = null;
try {
Class.forName("org.hsqldb.jdbcDriver" );
} catch (Exception e) {
System.out.println("ERROR: failed to load HSQLDB JDBC driver.");
e.printStackTrace();
return;
}
try {
conn = DriverManager.getConnection("jdbc:hsqldb:file:/home/bladimir/Pacientes/Pacientes", "bladimir", "2704");
st = conn.createStatement();
try {
String a = jTextField1.getText().toString();
String b = jTextField2.getText().toString();
String c = jTextField3.getText().toString();
String d = jTextField4.getText().toString();
String e = jTextField5.getText().toString();
String f = jTextField6.getText().toString();
PreparedStatement preparedStatement = conn.prepareStatement("INSERT INTO pacientes (nombre, ci, fechanac, ingreso, ultima, proxima) VALUES (?, ?, ?, ?, ?, ?)");
//Preparamos aprovechando que en a, b, c, d, e, f tenemos los strings a insertar
preparedStatement.setString(1, a);
preparedStatement.setString(1, b);
preparedStatement.setString(1, c);
preparedStatement.setString(1, d);
preparedStatement.setString(1, e);
preparedStatement.setString(1, f);
preparedStatement.executeUpdate(); //Ejecutamos
} catch (SQLException e) {
System.out.println("Error de MySQL: " + e.getMessage());
}
jTextField1.setText("");
jTextField1.setEditable(false);
jTextField2.setText("");
jTextField2.setEditable(false);
jTextField3.setText("");
jTextField3.setEditable(false);
jTextField4.setText("");
jTextField4.setEditable(false);
jTextField4.setText("");
jTextField5.setEditable(false);
jTextField5.setText("");
jTextField6.setEditable(false);
jTextField6.setText("");
rst1.close();
st.executeUpdate("SHUTDOWN");
st.close();
conn.close();
cargarlista();
} catch (Exception ex){
return;
}
}
private void cargarlista() {
// TODO Auto-generated method stub
Connection conn = null;
ResultSet rs = null;
Statement st = null;
try {
Class.forName("org.hsqldb.jdbcDriver" );
conn = DriverManager.getConnection("jdbc:hsqldb:file:/home/bladimir/Pacientes/Pacientes", "bladimir", "2704");
st = conn.createStatement();
rs = st.executeQuery ("select nombre from pacientes");
while(rs.next()){
String tmpStrObtenido = rs.getString("nombre");
choice1.addItem((String) makeObj(tmpStrObtenido));
}
rs.close();
} catch (Exception e) {
System.out.println("ERROR: failed to load HSQLDB JDBC driver.");
e.printStackTrace();
return;
}
}
private Object makeObj(final String item) {
return new Object() { public String toString() { return item; } };
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SQLException {
/* 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())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Inicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Inicio().setVisible(true);
}
});
}
private void cargarjcombobox(String consulta) {
}
private void conocernumeroreg() {
Connection conn = null;
Statement st = null;
String sql = null;
ResultSet rst1 = null;
try {
Class.forName("org.hsqldb.jdbcDriver");
conn = DriverManager.getConnection("jdbc:hsqldb:file:/home/bladimir/Pacientes/Pacientes", "bladimir", "2704");
} catch (Exception ex){
System.err.println("Se ha producido un error al cargar el controlador JDBC");
return;
}
try {
st = conn.createStatement();
sql = "Select COUNT(ID) from PACIENTES";
rst1 = st.executeQuery(sql);
while(rst1.next()){
r=rst1.getInt(1);
}
rst1.close();
st.executeUpdate("SHUTDOWN");
st.close();
conn.close();
} catch (Exception ex){
return;
}
}
private void fechahoy() {
SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
jTextField4.setText(formateador.format(new Date()));
}
}