Está en la página 1de 4

Nota: AJUSTAR CODIGO DE ACUERDO A PROYECTO

txtControl
txtNombre

txtSemestre cmdMostrar2

txtEspecialidad

txtTutor

cmdEliminar jButton2

Formulario
Ejecutado
package proyectojlem;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
*
* @author Estradajdl
*/
public class FormEliminar extends javax.swing.JFrame {

public FormEliminar() {
initComponents();

this.txtNombre.setVisible(false);
this.txtEspecialidad.setVisible(false);
this.txtSemestre.setVisible(false);
this.txtTutor.setVisible(false); Código que OCULTA los cuadros de
//this.jLabel2.setVisible(false); texto así como las etiquetas.
this.jLabel3.setVisible(false);
this.jLabel4.setVisible(false);
this.jLabel5.setVisible(false);
this.jLabel6.setVisible(false);

private void cmdEliminarMouseClicked(java.awt.event.MouseEvent evt) {

try {
try (Connection conexion1 =
DriverManager.getConnection("jdbc:mysql://localhost/xoxo29","root" ,"")) {
Statement comando=conexion1.createStatement();
comando.executeUpdate("delete from alumnos where numControl ="+txtControl.getText() );
}

lblresultados.setText("Se Elimino el registro"); Código que ELIMINA el registro


txtNombre.setText(""); seleccionado de la base de datos,
txtSemestre.setText(""); siempre y cuando encuentre el
txtEspecialidad.setText(""); registro buscado.
txtTutor.setText("");

} catch(SQLException ex){
setTitle(ex.toString());
}

private void cmdMostrar2MouseClicked(java.awt.event.MouseEvent evt) {


try {
try (Connection conexion =
DriverManager.getConnection("jdbc:mysql://localhost/xoxo29","root" ,"")) {
Statement comando=conexion.createStatement();
ResultSet registro = comando.executeQuery("select nombre,semestre,
especialidad, Tutor from alumnos where numcontrol="+txtControl.getText());
if (registro.next()==true) {
txtNombre.setVisible(true);
txtEspecialidad.setVisible(true);
txtSemestre.setVisible(true);
txtTutor.setVisible(true);
jLabel2.setVisible(true);
Código que MUESTRA los cuadros de
jLabel3.setVisible(true);
texto así como las etiquetas, al
jLabel4.setVisible(true);
jLabel5.setVisible(true); momento de mostrar los datos del
jLabel6.setVisible(true); registro solicitado.

txtNombre.setText(registro.getString("nombre"));
txtSemestre.setText(registro.getString("semestre"));
txtEspecialidad.setText(registro.getString("especialidad"));
txtTutor.setText(registro.getString("Tutor")); Código que MUESTRA los valores
almacenados en los campos de la
} else {
base de datos hacia los cuadros de
lblresultados.setText("No existe el alumno
solicitado"); texto.

}
}
} catch(SQLException ex){
setTitle(ex.toString());
}
}

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {


Menu RM = new Menu();
RM.setVisible(true);
dispose();
}

private void cargarDriver() {


try {
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception ex) {
setTitle(ex.toString());
}
}
public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FormEliminar().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton cmdEliminar;
private javax.swing.JButton cmdMostrar2;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel lblResult;
private javax.swing.JLabel lblresultados;
private javax.swing.JTextField txtControl;
private javax.swing.JTextField txtEspecialidad;
private javax.swing.JTextField txtNombre;
private javax.swing.JTextField txtSemestre;
private javax.swing.JTextField txtTutor;
// End of variables declaration
}

También podría gustarte