Java - No conecta el netbeans al access

 
Vista:
Imágen de perfil de Jorge

No conecta el netbeans al access

Publicado por Jorge (10 intervenciones) el 03/04/2016 00:36:46
Estoy haciendo un ejercicio con en java con el IDE Netbeans con conexión al access y al guardar me sale un error.
Al parecer no conecta o no encuentra la base de datos de access que se encuentra en el directorio raíz C:\mante.accdb.
Errores

El código de este tema es:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.awt.HeadlessException;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
 
public class ModuEquipo extends javax.swing.JFrame {
 Connection con;
 ResultSet r;
 CallableStatement st;
    public ModuEquipo() {
    initComponents();
 
    DefaultTableModel model = new DefaultTableModel();
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con=DriverManager.getConnection("jdbc:odbc:mante");
 
        JOptionPane.showMessageDialog(null,"conectado");
        }catch(Exception ex){}
 
    }
public void guardar()
    {
        String idEqu    =this.jTextField1.getText();
        String DesEqui  =this.jTextField2.getText();
        String MarEqui  =this.jTextField3.getText();
        String Serie    =this.jTextField4.getText();
        String Potencia =this.jTextField5.getText();
        String FechaFa  =this.jTextField6.getText();
 
        try{
        st=con.prepareCall("{call ingresar(?,?,?,?,?,?)}");
        st.setString(1,idEqu );
        st.setString(2,DesEqui );
        st.setString(3,MarEqui);
        st.setString(4,Serie);
        st.setString(5,Potencia);
        st.setString(6,FechaFa);
        int rta=st.executeUpdate();
        if(rta==1)
        {
            JOptionPane.showMessageDialog(null, "Datos guardados correctamente");
        }
        }catch(Exception ex){JOptionPane.showMessageDialog(null,"NO se guardo correctamente");
 
 
    }
 
     public void mostrar()
    {
        DefaultTableModel tabla =new DefaultTableModel();
        try{
        tabla.addColumn("Código");
        tabla.addColumn("Nombre");
        tabla.addColumn("Marca");
        tabla.addColumn("Serie");
        tabla.addColumn("Potencia");
        tabla.addColumn("Fecha Fabri.");
        st=con.prepareCall("{call mostrar}");
 
        r=st.executeQuery();
        while (r.next()){
        Object dato[]=new  Object[6];
        for (int i=0; i<6; i++){
           dato[i]=r.getString(i+1);
 
       }
       tabla.addRow(dato);
       }
       this.jTable1.setModel(tabla);
 
 
 
        }catch(Exception ex){JOptionPane.showMessageDialog(null, ex);}
    }
 
     public void buscar()
     {
         String nom=this.jTextField1.getText();
         try{
         st=con.prepareCall("{call buscar(?)}");
         st.setString(1, nom);
         r=st.executeQuery();
         if(r.next())
         {
             JOptionPane.showMessageDialog(null, "Datos encontrados ");
             this.jTextField1.setText(r.getString(1));
             this.jTextField2.setText(r.getString(2));
             this.jTextField3.setText(r.getString(3));
             this.jTextField4.setText(r.getString(4));
             this.jTextField5.setText(r.getString(5));
             this.jTextField6.setText(r.getString(6));
 
 
         }
         else
         {
             JOptionPane.showMessageDialog(null,"no se encontraron los datos");
         }
         }catch(Exception ex)
         {}
 
     }
 
 
     public void modificar()
    {
        String idEqu    =this.jTextField1.getText();
        String DesEqui  =this.jTextField2.getText();
        String MarEqui  =this.jTextField3.getText();
        String Serie    =this.jTextField4.getText();
        String Potencia =this.jTextField5.getText();
        String FechaFa  =this.jTextField6.getText();
 
        try{
        st=con.prepareCall("{call modificar(?,?,?,?,?,?)}");
 
        st.setString(1,idEqu );
        st.setString(2,DesEqui );
        st.setString(3,MarEqui);
        st.setString(4,Serie);
        st.setString(5,Potencia);
        st.setString(6,FechaFa);
 
        int rta=st.executeUpdate();
        if(rta==1)
        {
            JOptionPane.showMessageDialog(null, "Datos guardados correctamente");
        }
        }catch(Exception ex){JOptionPane.showMessageDialog(null, "NO se guardo correamente");}
 
 
    }
 
 
     public void eliminar()
     {
        String nom=this.jTextField1.getText();
        try {
            st=con.prepareCall("{call eliminar(?)}");
            st.setString(1, nom);
            int rpta=st.executeUpdate();
 
            if(rpta==1){
            JOptionPane.showMessageDialog(this, "Dato Eliminado","Aviso",JOptionPane.INFORMATION_MESSAGE);
 
 
            }else {
             JOptionPane.showMessageDialog(this, "Dato No Eliminado","Aviso",JOptionPane.ERROR_MESSAGE);
 
            }
 
        } catch (SQLException | HeadlessException e) {JOptionPane.showMessageDialog(this, e.toString());
        }
 
     }

Imagen-Ingreso
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 755
Bronce
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

No conecta el netbeans al access

Publicado por Yamil Bracho (2315 intervenciones) el 03/04/2016 00:54:55
Imprimi siempre las excepción para saber cual es el error. Por ejemplo :

1
2
3
4
5
....
} catch(Exception ex){
   ex.printStackTrace();
  JOptionPane.showMessageDialog(null, "NO se guardo correamente");
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Jorge

No conecta el netbeans al access

Publicado por Jorge (10 intervenciones) el 03/04/2016 01:38:18
Sigue el mismo error

pero sale un aviso y me envía a la siguiente linea, puede que sea que no reconoce el Path donde se encuentra el archivo de access
hay otra manera de conectarse al access.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public void guardar()
    {
        String idEqu    =this.jTextField1.getText();
        String DesEqui  =this.jTextField2.getText();
        String MarEqui  =this.jTextField3.getText();
        String Serie    =this.jTextField4.getText();
        String Potencia =this.jTextField5.getText();
        String FechaFa  =this.jTextField6.getText();
 
        try{
        st=con.prepareCall("{call ingresar(?,?,?,?,?,?)}"); ( ME ENVÍA A ESTA LINEA )
        st.setString(1,idEqu );
        st.setString(2,DesEqui );
        st.setString(3,MarEqui);
        st.setString(4,Serie);
        st.setString(5,Potencia);
        st.setString(6,FechaFa);
        int rta=st.executeUpdate();
        if(rta==1)
        {
            JOptionPane.showMessageDialog(null, "Datos guardados correctamente");
        }
 
        } catch(SQLException | HeadlessException ex){
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "NO se guardo correamente");
        }
 
    }
 
     public void mostrar()
    {
        DefaultTableModel tabla =new DefaultTableModel();
        try{
        tabla.addColumn("Código");
        tabla.addColumn("Nombre");
        tabla.addColumn("Marca");
        tabla.addColumn("Serie");
        tabla.addColumn("Potencia");
        tabla.addColumn("Fecha Fabri.");
        st=con.prepareCall("{call mostrar}");
        r=st.executeQuery();
        while (r.next()){
        Object dato[]=new  Object[6];
        for (int i=0; i<6; i++){
           dato[i]=r.getString(i+1);
      }
       tabla.addRow(dato);
       }
       this.jTable1.setModel(tabla);
 
        } catch(Exception ex){
         ex.printStackTrace();
         JOptionPane.showMessageDialog(null, "NO se guardo correctamente");
 
        }
    }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 755
Bronce
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

No conecta el netbeans al access

Publicado por Yamil Bracho (2315 intervenciones) el 03/04/2016 03:53:45
Revisa en el log de Netbeans que excepción fue la que ocurrió...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

No conecta el netbeans al access

Publicado por Luis nieto (11 intervenciones) el 03/04/2016 18:00:15
Tienes que usar JDBC o ucanacces para conectarte a access si usas jdbc la version de java debe estar debajo del 8 puedes descargar java 7_79
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Jorge

No conecta el netbeans al access

Publicado por Jorge (10 intervenciones) el 03/04/2016 19:51:03
Estoy utilizando el Java 7u79-windows-i586 y el Netbeans 7.2
Estoy buscando la solución pero por ahi dentro del codigo me debe faltar algo.
A partir del Java 8 se utiliza las librerías ucanaccess o debo utilizar ya esta librería
Gracias por la respuesta
Jorge
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

No conecta el netbeans al access

Publicado por Oswaldo (1 intervención) el 04/04/2016 03:44:47
Conexion a access con java 8.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
try {
			Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
			Connection conexion = DriverManager.getConnection(LAURL);
			if (conexion != null) {
				System.out.println("Conexion exitosa");
			} else {
				System.out.println("No se pudo conectar");
			}
			Statement stm = conexion.createStatement();
			boolean y = stm.execute("CREATE TABLE example1 (id COUNTER PRIMARY KEY,descr text(400), number numeric(12,3), date0 datetime) ");
		    if( y == true) {
				System.out.println("Se a creado la base de tabla");
			} else {
				System.out.println("Error no se acreado la tabla");
			}
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			System.out.println(e.getCause());
		}

Variable a ocupar en la conexion .

1
private final static String LAURL = "jdbc:ucanaccess://C:/Users/AlejandroPCS/Desktop/labase.mdb";

librerias
link de descarga de librerias. https://sourceforge.net/projects/ucanaccess/files/

dc6ad4588d6b8cc1fb47d8391ff21684o
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar