Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package aerolinea;
- import aerolinea.Ventanas.Pasajero;
- import java.sql.*;
- import javax.swing.JOptionPane;
- /**
- *Cliente
- * @author others
- * se crea el cliente
- */
- public class Cliente {
- public String nombre;
- public int cedula;
- public int telefono;
- public String correo;
- /**
- * Datos ´personales del cliente
- * @param nombre Nombre del cliente
- * @param cedula cedukla del cliente
- * @param telefono telefono del cliente
- * @param correo correo del cliente
- */
- public Cliente(String nombre, int cedula, int telefono, String correo) {
- this.nombre = nombre;
- this.cedula = cedula;
- this.telefono = telefono;
- this.correo = correo;
- }
- public Cliente() {
- }
- /**
- * Se imprime los datos del cliente
- */
- public void p(){
- System.out.println(this.nombre);
- System.out.println(this.cedula);
- System.out.println(this.telefono);
- System.out.println(this.correo);
- }
- public void registro(){
- Pasajero pa = new Pasajero();
- try {
- Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/proyectoavion", "root", "");
- PreparedStatement pst = cn.prepareStatement("insert into pasajeros values (?,?,?,?)");
- pst.setString(1, pa.campoNombre.getText());
- pst.setString(2, pa.campoID.getText());
- pst.setString(3, pa.campoTel.getText());
- pst.setString(4,pa.campoEmail.getText());
- pst.executeUpdate();
- pa.campoNombre.setText("");
- pa.campoID.setText("");
- pa.campoTel.setText("");
- pa.campoEmail.setText("");
- pa.si.setText("Registrado");
- } catch (SQLException ex) {
- System.out.println(ex.getMessage());
- }
- }
- public void buscar (){
- Pasajero pa = new Pasajero();
- try{
- Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/proyectoavion", "root","");
- PreparedStatement pst = cn.prepareStatement("select * from pasajeros where Cedula = ?");
- pst.setString(1, pa.campoBuscar.getText());
- ResultSet re = pst.executeQuery();
- if(re.next()){
- pa.campoNombre.setText(re.getString("Nombre"));
- pa.campoID.setText(re.getString("Cedula"));
- pa.campoTel.setText(re.getString("Telefono"));
- pa.campoEmail.setText(re.getString("Correo"));
- }
- else{
- JOptionPane.showMessageDialog(null,"No se encuentra registrado!!");
- }
- }
- catch(SQLException e){
- System.out.println(e.getMessage());
- }
- }
- public void modificar (){
- Pasajero pa = new Pasajero();
- try{
- String si= pa.campoBuscar.getText();
- Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/proyectoavion", "root","");
- PreparedStatement pst = cn.prepareStatement("update pasajeros set Nombre=?, Telefono = ?, correo = ? where Cedula="+si);
- pst.setString(1,pa.campoNombre.getText().trim());
- pst.setString(2, pa.campoTel.getText().trim());
- pst.setString(3, pa.campoEmail.getText().trim());
- pst.executeUpdate();
- pa.campoNombre.setText("");
- pa.campoTel.setText("");
- pa.campoEmail.setText("");
- pa.campoBuscar.setText("");
- pa.campoID.setText("");
- pa.si.setText("Modificado");
- }
- catch(SQLException e){
- System.out.println(e.getMessage());
- }
- }
- public void eliminar (){
- Pasajero pa = new Pasajero();
- try{
- Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/proyectoavion", "root","");
- PreparedStatement pst = cn.prepareStatement("delete from pasajeros where Cedula = ?");
- pst.setString(1,pa.campoBuscar.getText().trim());
- pst.executeUpdate();
- pa.campoNombre.setText("");
- pa.campoID.setText("");
- pa.campoTel.setText("");
- pa.campoEmail.setText("");
- pa.si.setText("Eliminado");
- }
- catch(SQLException e){
- System.out.println(e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment