Advertisement
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 JFrames;
- import Project.App;
- import Project.Driver;
- import Project.Users;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Date;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Utilizador
- */
- public class EditarPerfil extends javax.swing.JFrame {
- Users currentUser;
- Driver currentDriver;
- App app;
- int userId;
- private final String url = "jdbc:postgresql://localhost:5432/RideOnCar";
- private final String user = "borys";
- private final String password = "qwerty";
- public Connection connect() throws SQLException {
- return DriverManager.getConnection(url, user, password);
- }
- /**
- * Creates new form EditarPerfil
- * @param currentUser
- */
- public EditarPerfil(Users currentUser) throws SQLException {
- this.currentUser = currentUser;
- userId = currentUser.getUserId();
- currentDriver = new Driver();
- app = new App();
- initComponents();
- myComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jScrollPane1 = new javax.swing.JScrollPane();
- jEditorPane1 = new javax.swing.JEditorPane();
- jLabel3 = new javax.swing.JLabel();
- textFieldJob = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- textFieldName = new javax.swing.JTextField();
- textFieldCar = new javax.swing.JTextField();
- labelNome = new javax.swing.JLabel();
- jButtonGuardar = new javax.swing.JButton();
- labelEmail = new javax.swing.JLabel();
- jButtonSair = new javax.swing.JButton();
- textFieldEmail = new javax.swing.JTextField();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- textFieldAge = new javax.swing.JTextField();
- passwordField = new javax.swing.JPasswordField();
- jLabel5 = new javax.swing.JLabel();
- textFieldLicense = new javax.swing.JTextField();
- jComboBox1 = new javax.swing.JComboBox();
- jLabel6 = new javax.swing.JLabel();
- jDateChooser1 = new com.toedter.calendar.JDateChooser();
- jLabel7 = new javax.swing.JLabel();
- jScrollPane1.setViewportView(jEditorPane1);
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel3.setText("Profissão");
- textFieldJob.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textFieldJobActionPerformed(evt);
- }
- });
- jLabel4.setText("Carro");
- textFieldName.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textFieldNameActionPerformed(evt);
- }
- });
- textFieldCar.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- textFieldCarMouseClicked(evt);
- }
- });
- textFieldCar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textFieldCarActionPerformed(evt);
- }
- });
- labelNome.setText("Nome");
- jButtonGuardar.setText("Guardar");
- jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonGuardarActionPerformed(evt);
- }
- });
- labelEmail.setText("Email");
- jButtonSair.setText("Sair");
- jButtonSair.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButtonSairActionPerformed(evt);
- }
- });
- textFieldEmail.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textFieldEmailActionPerformed(evt);
- }
- });
- jLabel1.setText("Palavra-passe");
- jLabel2.setText("Idade");
- textFieldAge.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textFieldAgeActionPerformed(evt);
- }
- });
- passwordField.setText("jPasswordField1");
- passwordField.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- passwordFieldActionPerformed(evt);
- }
- });
- jLabel5.setText("Nº Carta Condução");
- textFieldLicense.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- textFieldLicenseMouseClicked(evt);
- }
- });
- textFieldLicense.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textFieldLicenseActionPerformed(evt);
- }
- });
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione", "B1", "B", "C1", "C", "D1", "D", "BE", "C1E", "CE", "D1E", "DE" }));
- jComboBox1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jComboBox1MouseClicked(evt);
- }
- });
- jComboBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox1ActionPerformed(evt);
- }
- });
- jLabel6.setText("Categoria");
- jDateChooser1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jDateChooser1MouseClicked(evt);
- }
- });
- jLabel7.setText("Data Validade");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(22, 22, 22)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(1, 1, 1)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(textFieldAge, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(textFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(textFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(textFieldJob, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(118, 118, 118))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(jButtonSair))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(textFieldCar)
- .addComponent(textFieldLicense)
- .addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))
- .addGap(93, 93, 93)
- .addComponent(jLabel6)
- .addGap(18, 18, 18)
- .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addGap(18, 18, 18))))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(labelEmail)
- .addComponent(labelNome)
- .addComponent(jLabel1)
- .addComponent(jLabel2)
- .addComponent(jLabel3)
- .addComponent(jLabel4))
- .addGap(18, 18, Short.MAX_VALUE)))
- .addComponent(jButtonGuardar))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel7)
- .addGap(0, 0, Short.MAX_VALUE)))
- .addGap(94, 94, 94))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(20, 20, 20)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(labelNome)
- .addGap(18, 18, 18)
- .addComponent(labelEmail)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(textFieldAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2)))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(textFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(textFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(83, 83, 83)))
- .addGap(24, 24, 24)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(textFieldJob, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(41, 41, 41)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(textFieldCar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(23, 23, 23)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel5)
- .addComponent(textFieldLicense, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel7)
- .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
- .addComponent(jButtonSair)
- .addGap(21, 21, 21))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButtonGuardar)
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void textFieldJobActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void textFieldNameActionPerformed(java.awt.event.ActionEvent evt) {
- }
- private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {
- String name = textFieldName.getText();
- String email = textFieldEmail.getText();
- String job = textFieldJob.getText();
- String password = passwordField.getText();
- int age = 0;
- //gets Age from text field
- try {
- age = Integer.parseInt(textFieldAge.getText());
- }
- catch(NumberFormatException ex) {
- System.out.println("Exception: " +ex);
- }
- //gets Driver details
- try {
- currentUser.saveProfile(name, email, age, job, password);
- } catch (SQLException ex) {
- Logger.getLogger(EditarPerfil.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- if (currentDriver.updateDriver(currentUser.getUserId(), Integer.parseInt(textFieldLicense.getText()), jDateChooser1.getDate(), String.valueOf(jComboBox1.getSelectedItem()), textFieldCar.getText()) == true) {
- JOptionPane.showMessageDialog(null, "Informação alterada com sucesso");
- }
- } catch (java.lang.NumberFormatException e) {
- JOptionPane.showMessageDialog(null, "Introduza número de carta válido");
- } catch (java.lang.NullPointerException e) {
- JOptionPane.showMessageDialog(null, "Selecione uma data válida!!");
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "Selecione uma categoria válida!!");
- }
- try {
- new UsersFrame(currentUser).setVisible(true);
- this.dispose();
- } catch (SQLException ex) {
- Logger.getLogger(EditarPerfil.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void textFieldEmailActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void textFieldAgeActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButtonSairActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- new UsersFrame(currentUser).setVisible(true);
- this.dispose();
- } catch (SQLException ex) {
- Logger.getLogger(EditarPerfil.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void passwordFieldActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void textFieldCarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void textFieldCarMouseClicked(java.awt.event.MouseEvent evt) {
- try {
- if(app.verificarCondutor(userId) == false){
- new Condutor(currentUser).setVisible(true);
- this.dispose();
- }
- } catch (SQLException ex) {
- Logger.getLogger(EditarPerfil.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void textFieldLicenseMouseClicked(java.awt.event.MouseEvent evt) {
- try {
- if(app.verificarCondutor(userId) == false){
- new Condutor(currentUser).setVisible(true);
- this.dispose();
- }
- } catch (SQLException ex) {
- Logger.getLogger(EditarPerfil.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void jComboBox1MouseClicked(java.awt.event.MouseEvent evt) {
- try {
- if(app.verificarCondutor(userId) == false){
- new Condutor(currentUser).setVisible(true);
- this.dispose();
- }
- } catch (SQLException ex) {
- Logger.getLogger(EditarPerfil.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void jDateChooser1MouseClicked(java.awt.event.MouseEvent evt) {
- try {
- if(app.verificarCondutor(userId) == false){
- new Condutor(currentUser).setVisible(true);
- this.dispose();
- }
- } catch (SQLException ex) {
- Logger.getLogger(EditarPerfil.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void textFieldLicenseActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(EditarPerfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(EditarPerfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(EditarPerfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(EditarPerfil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- //new EditarPerfil().setVisible(true);
- }
- });
- }
- private void myComponents() throws SQLException {
- //Nome
- try (Connection conn = this.connect()) {
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT username FROM users WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String username = rs.getString("username");
- textFieldName.setText(username);
- System.out.println(username);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- //Email
- try (Connection conn = this.connect()){
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT email FROM users WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String email = rs.getString("email");
- textFieldEmail.setText(email);
- System.out.println(email);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- //Idade
- try (Connection conn = this.connect()){
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT age FROM users WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String idade = rs.getString("age");
- textFieldAge.setText(idade);
- System.out.println(idade);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- //Profissão
- try (Connection conn = this.connect()){
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT job FROM users WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String job = rs.getString("job");
- textFieldJob.setText(job);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- //Carro
- try (Connection conn = this.connect()){
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT job FROM users WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String profissao = rs.getString("job");
- textFieldJob.setText(profissao);
- System.out.println(profissao);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- //Retrieves password from database
- try (Connection conn = this.connect()){
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT password FROM users WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String password = rs.getString("password");
- passwordField.setText(password);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- //DRIVER
- //retrieves Car
- if(app.verificarCondutor(userId) == true){
- try (Connection conn = this.connect()){
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT car FROM driver WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String car = rs.getString("car");
- textFieldCar.setText(car);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- } else {
- textFieldCar.setEditable(false);
- }
- if(app.verificarCondutor(userId) == true){
- //retrieves number of Driving License
- try (Connection conn = this.connect()){
- Statement stmt = conn.createStatement();
- String selectSQL = ("SELECT n_card FROM driver WHERE userid = ?");
- PreparedStatement preparedStmt = conn.prepareStatement(selectSQL);
- preparedStmt.setInt(1, currentUser.getUserId());
- ResultSet rs = preparedStmt.executeQuery();
- while (rs.next()) {
- String license = rs.getString("n_card");
- textFieldLicense.setText(license);
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- throw e;
- }
- } else {
- textFieldLicense.setEditable(false);
- }
- //Retrieves category of driving license
- if(app.verificarCondutor(userId) == true){
- try (Connection conn = this.connect()) {
- Statement stmt = conn.createStatement();
- String sql = "select * from driver where userid= ?";
- PreparedStatement preparedStmt = conn.prepareStatement(sql);
- preparedStmt.setInt(1, userId);
- ResultSet rs = preparedStmt.executeQuery();
- if(rs.next()) {
- String category = rs.getString("category");
- jComboBox1.setSelectedItem(category);
- Date date = rs.getDate("date");
- jDateChooser1.setDate(date);
- String car = rs.getString("car");
- textFieldCar.setText(car);
- }
- }
- }
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButtonGuardar;
- private javax.swing.JButton jButtonSair;
- private javax.swing.JComboBox jComboBox1;
- private com.toedter.calendar.JDateChooser jDateChooser1;
- private javax.swing.JEditorPane jEditorPane1;
- 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.JScrollPane jScrollPane1;
- private javax.swing.JLabel labelEmail;
- private javax.swing.JLabel labelNome;
- private javax.swing.JPasswordField passwordField;
- private javax.swing.JTextField textFieldAge;
- private javax.swing.JTextField textFieldCar;
- private javax.swing.JTextField textFieldEmail;
- private javax.swing.JTextField textFieldJob;
- private javax.swing.JTextField textFieldLicense;
- private javax.swing.JTextField textFieldName;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement