Java - mantener la conexión en un .jar de java con jdb

 
Vista:

mantener la conexión en un .jar de java con jdb

Publicado por Edgar (2 intervenciones) el 03/06/2011 10:27:07
Hola q tal
bueno mi duda es la sigueinte
yo tengo realizado una aplicacion en Java (con GUI) que realiza una conexion con SQL por medio de JDBC.
no tengo ningun problema en las consultas, todo lo realiza a la perfeccion cada que compilo mi aplicacion desde BlueJ, el problema inicia cuando yo creo el archivo .jar o .exe para ejecutar sin necesidad del editor, pero resulta que se ejecuta sin problemas la gui pero ya no realiza las consultas, pareciera que pierde la conexion con mi BD.
que es lo que me hace falta en mi codigo para que el conector siga activo?
espero me puedan ayudar y me explique claramente
gracias por su ayuda !!!!!!
saludos.

aqui dejo una de mis 4 clases en las cuales mando llamar al conector
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
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class Acceso extends JFrame
{
// instance variables - replace the example below with your own 
static JTextField tfncontrol, tfnom, tfesp, tfgp, tfpl, tfma, tfmo, tfco;
public Acceso(String titulo,int x, int y, int ancho, int alto)
{
super(titulo);
this.setBounds(x,y,ancho,alto);
this.getContentPane().setLayout(null);
this.setVisible(true);
JButton jbt3 = new JButton("Guardar");
jbt3.setBounds(780,130,120,20);
this.add(jbt3);
JLabel jlncontrol = new JLabel("N° Control: ");
jlncontrol.setBounds(10,15,160,20);
this.add(jlncontrol);
tfncontrol = new JTextField("");
tfncontrol.setBounds(10,38,120,20);
this.add(tfncontrol);
JLabel jlnom = new JLabel("Nombre: ");
jlnom.setBounds(170,15,120,20);
this.add(jlnom);
tfnom = new JTextField("");
tfnom.setBounds(170,38,220,20);
this.add(tfnom);
JLabel jlesp = new JLabel("Especialidad: ");
jlesp.setBounds(430,15,120,20);
this.add(jlesp);
tfesp = new JTextField("");
tfesp.setBounds(430,38,120,20);
this.add(tfesp);
JLabel jlgp = new JLabel("Grupo: ");
jlgp.setBounds(590,15,120,20);
this.add(jlgp);
tfgp = new JTextField("");
tfgp.setBounds(590,38,120,20);
this.add(tfgp);
JLabel jlpl = new JLabel("Placas: ");
jlpl.setBounds(10,80,120,20);
this.add(jlpl);
tfpl = new JTextField("");
tfpl.setBounds(10,100,120,20);
this.add(tfpl);
JLabel jlma = new JLabel("Marca: ");
jlma.setBounds(170,80,120,20);
this.add(jlma);
tfma = new JTextField("");
tfma.setBounds(170,100,120,20);
this.add(tfma);
JLabel jlmo = new JLabel("Modelo: ");
jlmo.setBounds(330,80,120,20);
this.add(jlmo);
tfmo = new JTextField("");
tfmo.setBounds(330,100,120,20);
this.add(tfmo);
JLabel jlco = new JLabel("Color: ");
jlco.setBounds(490,80,120,20);
this.add(jlco);
tfco = new JTextField("");
tfco.setBounds(490,100,120,20);
this.add(tfco);
JLabel jlregistro = new JLabel("Tabla de Registros ");
jlregistro.setBounds(10,160,140,20);
this.add(jlregistro);
Object[][] data = {
{"09106004", "JAVIER CARREON TREJO", "Sistemas","PYN727", "TOYOTA",new Integer(94),"Gris"},
{"08106123", "ANGEL MARTINEZ CONTRERAS", "Sistemas","GHL370", "VW",new Integer(99),"gris"},
};
String[] columnNames = {"N° Control", "Nombre", "Especialidad",
"Placas", "Marca","Modelo","Color"};
final JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(10, 190, 900, 100);
add(scrollPane);
JButton jbt1 = new JButton("Nuevo Registro");
jbt1.setBounds(780,300,120,20);
this.add(jbt1);
B3 b1 = new B3(this);
jbt1.addActionListener(b1);
JButton jbt2 = new JButton("crear consulta");
jbt2.setBounds(630,130,140,20);
this.add(jbt2);
jbt2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try {
//Comecta driver 
Class.forName("com.mysql.jdbc.Driver");
String usr="root";
String pwd="";
//Realiza conección 
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/vehicular", "root", "");
// create a statement, execute your query 
Statement statement = con.createStatement();
/*String gb = prub.getText(); 
* int numero=Integer.parseInt(gb);*/
//Consulta SQL 
ResultSet rs = statement.executeQuery("SELECT n_control,nombre, carrera, grupo, placas, modelo,marca,color FROM alumnos where n_control ="+tfncontrol.getText());
String sal = new String();
while(rs.next()){
sal = rs.getString("nombre");
tfnom.setText(sal);
sal = rs.getString("carrera");
tfesp.setText(sal);
sal = rs.getString("grupo");
tfgp.setText(sal);
sal = rs.getString("placas");
tfpl.setText(sal);
sal = rs.getString("modelo");
tfmo.setText(sal);
sal = rs.getString("marca");
tfma.setText(sal);
sal = rs.getString("color");
tfco.setText(sal);
}
rs.close();
con.close();
}
catch (SQLException sqle) {
System.out.println("Error de MySQL: " + sqle.getMessage());
}
catch (Exception ed)
{ // Other exceptions should be properly caught, but this'll do for an example 
ed.printStackTrace();
}
}
}
);
this.setVisible(true);
}
}
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