Foros del Web » Programación para mayores de 30 ;) » Java »

JDBC con interfaz grafica, donde registrar

Estas en el tema de JDBC con interfaz grafica, donde registrar en el foro de Java en Foros del Web. JDBC con interfaz grafica, en que linea registrar el driver y establecer la conexion. solo eso. Tengo la duda en que linea se debe de ...
  #1 (permalink)  
Antiguo 05/03/2009, 18:36
 
Fecha de Ingreso: agosto-2008
Mensajes: 587
Antigüedad: 15 años, 8 meses
Puntos: 6
JDBC con interfaz grafica, donde registrar

JDBC con interfaz grafica, en que linea registrar el driver y establecer la conexion. solo eso.

Tengo la duda en que linea se debe de registrar el driver y establecer la conexion, ya que en modo consola se hace justo despues del public main, cosa que hago con interfaz grafica y me da error. solo necesito eso.

Registrar el driver

Establecer la conexion

Tengo este código.


Código PHP:

// Creado en Netbeans

public class NewJFrame extends javax.swing.JFrame {

    
/** Creates new form NewJFrame */
    
public NewJFrame() {
        
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() {

        
jPanel1 = new javax.swing.JPanel();
        
jLabel1 = new javax.swing.JLabel();
        
jButton1 = new javax.swing.JButton();
        
jTextField1 = new javax.swing.JTextField();
        
jTextField2 = new javax.swing.JTextField();
        
jLabel2 = new javax.swing.JLabel();

        
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        
jLabel1.setText("Nombre:");

        
jButton1.setText("Insertar");

        
jLabel2.setText("Edad:");

        
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        
jPanel1.setLayout(jPanel1Layout);
        
jPanel1Layout.setHorizontalGroup(
            
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .
add(jPanel1Layout.createSequentialGroup()
                .
add(333333)
                .
add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .
add(jLabel1)
                    .
add(jLabel2))
                .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .
add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .
add(jButton1)
                    .
add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADINGfalse)
                        .
add(jTextField1)
                        .
add(jTextField2org.jdesktop.layout.GroupLayout.DEFAULT_SIZE90Short.MAX_VALUE)))
                .
addContainerGap(68Short.MAX_VALUE))
        );
        
jPanel1Layout.setVerticalGroup(
            
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .
add(jPanel1Layout.createSequentialGroup()
                .
add(212121)
                .
add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .
add(jLabel1)
                    .
add(jTextField1org.jdesktop.layout.GroupLayout.PREFERRED_SIZEorg.jdesktop.layout.GroupLayout.DEFAULT_SIZEorg.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .
addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .
add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .
add(jTextField2org.jdesktop.layout.GroupLayout.PREFERRED_SIZEorg.jdesktop.layout.GroupLayout.DEFAULT_SIZEorg.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .
add(jLabel2))
                .
add(181818)
                .
add(jButton1)
                .
addContainerGap(57Short.MAX_VALUE))
        );

        
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        
getContentPane().setLayout(layout);
        
layout.setHorizontalGroup(
            
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .
add(jPanel1org.jdesktop.layout.GroupLayout.DEFAULT_SIZEorg.jdesktop.layout.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
        );
        
layout.setVerticalGroup(
            
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .
add(jPanel1org.jdesktop.layout.GroupLayout.DEFAULT_SIZEorg.jdesktop.layout.GroupLayout.DEFAULT_SIZEShort.MAX_VALUE)
        );

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

    /**
    * @param args the command line arguments
    */
    
public static void main(String args[]) {
        
java.awt.EventQueue.invokeLater(new Runnable() {
            public 
void run() {
                new 
NewJFrame().setVisible(true);
            }
        });
    }

    
// Variables declaration - do not modify
    
private javax.swing.JButton jButton1;
    private 
javax.swing.JLabel jLabel1;
    private 
javax.swing.JLabel jLabel2;
    private 
javax.swing.JPanel jPanel1;
    private 
javax.swing.JTextField jTextField1;
    private 
javax.swing.JTextField jTextField2;
    
// End of variables declaration


  #2 (permalink)  
Antiguo 05/03/2009, 19:34
 
Fecha de Ingreso: agosto-2008
Mensajes: 587
Antigüedad: 15 años, 8 meses
Puntos: 6
Respuesta: JDBC con interfaz grafica, donde registrar

bueno ya me reconoce los driver y todo eso, pero no logro que me lanze la consulta a un jTextField1

Código PHP:
        try {

    
// cadena de conexion con la ruta fisica a la BD
String db "C:\\Documents and Settings\\Turbo\\Escritorio\\AccessBD_1.mdb";
// si la BD esta en la carpeta de la aplicacion Java
//String db = "AccessBD_1.mdb";
String url "jdbc:odbc:MS Access Database;DBQ=" db;

// registrar el driver JDBC usando el cargador de clases Class.forName
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("\nEstableciendo conexion...");
Connection con DriverManager.getConnection (url"""");
System.out.println("\nConexion establecida con: \"" db "\".");

Statement select con.createStatement();
ResultSet nombres select.executeQuery("SELECT nombre FROM tabla");

// aqui me da error, deberia de mostrar 1 solo registro en el JTextField1
// pero no lo hace.

String nombres JTextField1.getText(); 
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:16.