problema con cuenta registro de usario
Publicado por diego (3 intervenciones) el 04/04/2016 17:18:33
hola les cuento, estoy haciendo un programa en java que consta con una base de datos con usario y pass, cuando pongo el usario y pass en el programa me deriva a otra ventana, la cosa es que apesar que ponga un usario y pass que no existe me lo toma como si existen, cosa que no deveria
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
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.sql.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
public class Inicio extends JFrame {
private JPanel contentPane;
private JTextField txtusu;
private JTextField txtpass;
void minimazar(){
this.hide();
}
void cargaDriver() { //cargar(importar) el driver de JDBC de MySQL
try {
Class.forName("com.mysql.jdbc.Driver"); //forName dispara excepciones que si o si se deben capturar para no generar errores en tiempo de ejecucion y finalizar la aplicacion en forma abrupta
}catch(Exception ex) {
setTitle(ex.toString());
}
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Inicio frame = new Inicio();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Inicio() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblUsario = new JLabel("usario");
lblUsario.setBounds(64, 72, 46, 14);
contentPane.add(lblUsario);
JLabel lblPass = new JLabel("pass");
lblPass.setBounds(64, 129, 46, 14);
contentPane.add(lblPass);
txtusu = new JTextField();
txtusu.setBounds(149, 69, 164, 20);
contentPane.add(txtusu);
txtusu.setColumns(10);
JLabel lblResultado = new JLabel("");
lblResultado.setBounds(64, 10, 324, 50);
contentPane.add(lblResultado);
JButton btnAceptar = new JButton("aceptar");
btnAceptar.setFont(new Font("Tw Cen MT", Font.BOLD | Font.ITALIC, 17));
btnAceptar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lblResultado.setText("");
try
{
Connection conexion=DriverManager.getConnection("jdbc:mysql://localhost/usuarios", "root", "111188");
Statement comando=conexion.createStatement();
String sql = "SELECT * FROM usuarios WHERE usuario='"+txtusu+"' AND pass='"+txtpass+"'";
PreparedStatement ps = conexion.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
lblResultado.setText("Los datos han sido registrados");
txtusu.setText("");
txtpass.setText("");
Menu frame = new Menu();
frame.show();
dispose();
}
catch(SQLException ex){
setTitle(ex.toString());
}
}
});
btnAceptar.setBounds(243, 210, 89, 23);
contentPane.add(btnAceptar);
txtpass = new JTextField();
txtpass.setBounds(149, 136, 164, 20);
contentPane.add(txtpass);
txtpass.setColumns(10);
JButton btnNuevoUsuario = new JButton("Nuevo Usuario");
btnNuevoUsuario.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Registro obj = new Registro();
obj.show();
minimazar();
}
});
btnNuevoUsuario.setFont(new Font("Tw Cen MT", Font.BOLD | Font.ITALIC, 17));
btnNuevoUsuario.setBounds(64, 210, 129, 23);
contentPane.add(btnNuevoUsuario);
}
}
Valora esta pregunta
0