Access DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package Formularios; | |
import java.sql.*; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.swing.JOptionPane; | |
import javax.swing.table.DefaultTableModel; | |
/** | |
* | |
* @author User | |
*/ | |
public class personal extends javax.swing.JFrame { | |
DefaultTableModel model; | |
/* ... */ | |
private void botonMostrarActionPerformed(java.awt.event.ActionEvent evt) { | |
try { | |
Boolean shouldClose = false; | |
if ( resultados == null ) { | |
String db="jdbc:odbc:Driver=Microsoft Access Driver (*.mdb);DBQ=c:/base.mdb"; | |
String sql="SELECT * FROM personal"; | |
Connection cn = DriverManager.getConnection(db,"",""); | |
Statement st = cn.createStatement(); | |
resultados = st.executeQuery(sql); | |
shouldClose = true; | |
} | |
while(resultados.next()){ | |
nombreMostrar.setText(resultados.getString(2)); | |
apellidoMostrar.setText(resultados.getString(3)); | |
telefonoMostrar.setText(resultados.getString(4)); | |
} | |
resultados.close(); /* tengo mis dudas respecto de cerrar el resultset, creeria que tenes que dejarlo abierto */ | |
if (shouldClose) { | |
st.close(); | |
cn.close(); | |
} | |
} catch (SQLException ex) { | |
Logger.getLogger(personal.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
/* .. */ | |
// End of variables declaration | |
ResultSet resultados=null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment