Java - AYUDA, como ingresar datos en MySQL con enclipse

 
Vista:
sin imagen de perfil

AYUDA, como ingresar datos en MySQL con enclipse

Publicado por Juan Carlos (3 intervenciones) el 16/09/2016 23:21:43
Conecte una base de datos de MySQL con eclipse para hacer un proyecto llamado "Password", pero al momento de dar a nuevo registro y llenar todos los campos que pide y dar al boton registrar me pone los mensajes que puse en:
1
2
3
4
5
} catch (SQLException ex) {
	JOptionPane.showMessageDialog(null,
	"No se logro establecer conexión con la base de datos.",
	"Error", JOptionPane.ERROR_MESSAGE);
}

Ayuda por favor
El código fuente de el JFrame de "Nuevo registro" 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package formularios;
 
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
 
import clases.BaseDeDatos;
 
public class Registros extends JFrame {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField txtUsuario;
	private JTextField txtCorreoEl;
	private JLabel lblTelefono;
	private JTextField txtNumeroTe;
	private JLabel lblCorreoElectrnico;
	private JTextField txtClavetl;
	private JLabel lblContraseña;
	private JTextField txtClave2;
	private JLabel lblConfirmarContrasea;
	private BaseDeDatos bd = null;
	private ResultSet rs = null;
	private JButton btRegistrarse;
	protected static final String SQL = null;
 
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Registros frame = new Registros();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
	 * Create the frame.
	 */
	public Registros() {
		setTitle("Nuevo registro");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 447, 293);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(0, 153, 153));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
 
		txtUsuario = new JTextField();
		txtUsuario.setBounds(194, 11, 216, 20);
		contentPane.add(txtUsuario);
		txtUsuario.setColumns(10);
 
		JLabel lblNombreDeUsuario = new JLabel("Nombre de usuario");
		lblNombreDeUsuario.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblNombreDeUsuario.setBounds(10, 14, 174, 14);
		contentPane.add(lblNombreDeUsuario);
 
		txtCorreoEl = new JTextField();
		txtCorreoEl.setBounds(194, 42, 216, 20);
		contentPane.add(txtCorreoEl);
		txtCorreoEl.setColumns(10);
 
		lblTelefono = new JLabel("N\u00FAmero de tel\u00E9fono");
		lblTelefono.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblTelefono.setBounds(10, 79, 174, 14);
		contentPane.add(lblTelefono);
 
		txtNumeroTe = new JTextField();
		txtNumeroTe.setBounds(194, 73, 216, 20);
		contentPane.add(txtNumeroTe);
		txtNumeroTe.setColumns(10);
 
		lblCorreoElectrnico = new JLabel("Correo Electr\u00F3nico");
		lblCorreoElectrnico.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblCorreoElectrnico.setBounds(10, 48, 132, 14);
		contentPane.add(lblCorreoElectrnico);
 
		txtClavetl = new JTextField();
		txtClavetl.setBounds(194, 104, 216, 20);
		contentPane.add(txtClavetl);
		txtClavetl.setColumns(10);
 
		lblContraseña = new JLabel("Contrase\u00F1a");
		lblContraseña.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblContraseña.setBounds(10, 110, 132, 14);
		contentPane.add(lblContraseña);
 
		txtClave2 = new JTextField();
		txtClave2.setBounds(194, 135, 216, 20);
		contentPane.add(txtClave2);
		txtClave2.setColumns(10);
 
		lblConfirmarContrasea = new JLabel("Confirmar contrase\u00F1a");
		lblConfirmarContrasea
				.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblConfirmarContrasea.setBounds(10, 141, 155, 14);
		contentPane.add(lblConfirmarContrasea);
 
		btRegistrarse = new JButton("REGISTRARSE");
		btRegistrarse.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				bd = new BaseDeDatos();
				String Usuario = txtUsuario.getText();
				String Numero = txtNumeroTe.getText();
				String Clavegg = txtClavetl.getText();
				String Contrase = txtClave2.getText();
				String Correo = txtCorreoEl.getText();
				String SQL = "INSERT INTO `usuarios` (`ID`, `Nombre_Usiario`, `Numero_telefono`, `Contra`, `correo_electronico`) VALUES (NULL, '"
						+ Usuario
						+ "', '"
						+ Numero
						+ "', '"
						+ Clavegg
						+ "', '"
						+ Correo + "')";
				rs = bd.Registrar(SQL);
				try {
					while (rs.next()) {
					}
					if (Clavegg != Contrase) {
						JOptionPane.showMessageDialog(null,
								"Las contraseñas no coinciden.", "Error",
								JOptionPane.INFORMATION_MESSAGE);
 
					} else {
						Login NuevoLogin = new Login();
						NuevoLogin.setVisible(true);
					}
				} catch (SQLException ex) {
					JOptionPane
							.showMessageDialog(
									null,
									"No se logro establecer conexión con la base de datos.",
									"Error", JOptionPane.ERROR_MESSAGE);
				} catch (Exception ex) {
					JOptionPane
							.showMessageDialog(
									null,
									"No se logro establecer conexión con la base de datos.",
									"Error", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		btRegistrarse.setForeground(new Color(102, 0, 153));
		btRegistrarse.setBounds(161, 192, 132, 41);
		contentPane.add(btRegistrarse);
	};
}
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

AYUDA, como ingresar datos en MySQL con enclipse

Publicado por Juan Carlos (3 intervenciones) el 17/09/2016 01:27:23
¡Muchas gracias !
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