java.sql.SQLException: No value specified for parameter 1-11(all of the textfields)

I am making software for managing and monitoring GP medical records. When user is logged and if he wants to change some details for instance, phone number, last name, etc. it gives me an error java.sql.SQLException: No value specified for perimeter 1-11.
Here is my code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package com.mycompany.mrms;
import java.awt.Color;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Types;
import javax.swing.JOptionPane;
/**
*
* @author patok
*/
public class Profile extends javax.swing.JFrame {
/**
* Creates new form Profile
*/
Color DefaultColor,ClickedColor;
private static final String USRNM = "root";
private static final String PASWD = "admin";
private static final String DATA_BASE = "jdbc:mysql://localhost:3306/db_mrms";
private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
Connection db_mrms = null;
PreparedStatement ps = null;
public Profile() {
initComponents();
DefaultColor = new Color(4,59,92);
ClickedColor = new Color(249,180,45);
jPanel5.setBackground(DefaultColor);
jPanel3.setBackground(ClickedColor);
jPanel6.setBackground(DefaultColor);
jPanel7.setBackground(DefaultColor);
jPanel8.setBackground(DefaultColor);
jPanel9.setBackground(DefaultColor);
}
/**
* 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() {
jPanel4 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jFirstName = new javax.swing.JTextField();
jMiddleName = new javax.swing.JTextField();
jLastName = new javax.swing.JTextField();
jPhone = new javax.swing.JTextField();
jNationality = new javax.swing.JTextField();
jCountry = new javax.swing.JTextField();
jCity = new javax.swing.JTextField();
jAddress = new javax.swing.JTextField();
jPostCode = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jComments = new javax.swing.JTextArea();
jLabel8 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel33 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel29 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel10 = new javax.swing.JPanel();
jLabel16 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jPanel6 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jPanel9 = new javax.swing.JPanel();
jLabel7 = new javax.swing.JLabel();
jPanel7 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jPanel8 = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) {
// TODO add your handling code here:
}
private void jLabel1MousePressed(java.awt.event.MouseEvent evt) {
}
private void jPanel5MouseEntered(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
jPanel5.setBackground(ClickedColor);
jPanel3.setBackground(DefaultColor);
jPanel6.setBackground(DefaultColor);
jPanel7.setBackground(DefaultColor);
jPanel8.setBackground(DefaultColor);
jPanel9.setBackground(DefaultColor);
}
private void jPanel3MousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
jPanel5.setBackground(DefaultColor);
jPanel3.setBackground(ClickedColor);
jPanel6.setBackground(DefaultColor);
jPanel7.setBackground(DefaultColor);
jPanel8.setBackground(DefaultColor);
jPanel9.setBackground(DefaultColor);
}
private void jPanel6MousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
jPanel5.setBackground(DefaultColor);
jPanel3.setBackground(DefaultColor);
jPanel6.setBackground(ClickedColor);
jPanel7.setBackground(DefaultColor);
jPanel8.setBackground(DefaultColor);
jPanel9.setBackground(DefaultColor);
}
private void jPanel9MousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
jPanel5.setBackground(DefaultColor);
jPanel3.setBackground(DefaultColor);
jPanel6.setBackground(DefaultColor);
jPanel7.setBackground(DefaultColor);
jPanel8.setBackground(DefaultColor);
jPanel9.setBackground(ClickedColor);
}
private void jPanel7MousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
jPanel5.setBackground(DefaultColor);
jPanel3.setBackground(DefaultColor);
jPanel6.setBackground(DefaultColor);
jPanel7.setBackground(ClickedColor);
jPanel8.setBackground(DefaultColor);
jPanel9.setBackground(DefaultColor);
}
private void jPanel8MousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
jPanel5.setBackground(DefaultColor);
jPanel3.setBackground(DefaultColor);
jPanel6.setBackground(DefaultColor);
jPanel7.setBackground(DefaultColor);
jPanel8.setBackground(ClickedColor);
jPanel9.setBackground(DefaultColor);
}
private void jPostCodeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String firstName = jFirstName.getText();
String middleName = jMiddleName.getText();
String lastName = jLastName.getText();
String phone = jPhone.getText();
String nationality = jNationality.getText();
String country = jCountry.getText();
String city = jCity.getText();
String address = jAddress.getText();
String postCode = jPostCode.getText();
String comments = jComments.getText();
if (middleName.equals("") && lastName.equals("") && phone.equals("") && nationality.equals("") && country.equals("") && city.equals("") && address.equals("") && postCode.equals("") && comments.equals("")) {
JOptionPane.showMessageDialog(null, "To update information, please fill some information into the textfields.");
} else {
try {
Class.forName(DRIVER);
db_mrms = DriverManager.getConnection(DATA_BASE, USRNM, PASWD);
String sql = "UPDATE patients SET ";
boolean isFirst = true;
if (!firstName.equals("")) { sql += "FirstName = IFNULL(?, FirstName), "; isFirst = false; }
if (!middleName.equals("")) { sql += "MiddleName = ?, "; isFirst = false; }
if (!lastName.equals("")) { sql += "LastName = ?, "; isFirst = false; }
if (!phone.equals("")) { sql += "Phone = ?, "; isFirst = false; }
if (!nationality.equals("")) { sql += "Nationality = ?, "; isFirst = false; }
if (!country.equals("")) { sql += "Country = ?, "; isFirst = false; }
if (!city.equals("")) { sql += "City = ?, "; isFirst = false; }
if (!address.equals("")) { sql += "Address = ?, "; isFirst = false; }
if (!postCode.equals("")) { sql += "PostCode = ?, "; isFirst = false; }
if (!comments.equals("")) { sql += "Comments = ?, "; isFirst = false; }
// Remove the trailing comma and space
sql = sql.substring(0, sql.length() - 2);
// Add the WHERE clause
sql += " WHERE PatientID = ?"; // Add your WHERE clause here
PreparedStatement ps = db_mrms.prepareStatement(sql);
int parameterIndex = 1;
if (!firstName.equals("")) { ps.setString(parameterIndex++, firstName); }
if (!middleName.equals("")) { ps.setString(parameterIndex++, middleName); }
if (!lastName.equals("")) { ps.setString(parameterIndex++, lastName); }
if (!phone.equals("")) { ps.setString(parameterIndex++, phone); }
if (!nationality.equals("")) { ps.setString(parameterIndex++, nationality); }
if (!country.equals("")) { ps.setString(parameterIndex++, country); }
if (!city.equals("")) { ps.setString(parameterIndex++, city); }
if (!address.equals("")) { ps.setString(parameterIndex++, address); }
if (!postCode.equals("")) { ps.setString(parameterIndex++, postCode); }
if (!comments.equals("")) { ps.setString(parameterIndex++, comments); }
int rowsAffected = ps.executeUpdate();
if (rowsAffected > 0) {
JOptionPane.showMessageDialog(null, "User Information Updated Successfully!");
setVisible(false);
new Profile().setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "No changes were made.");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
/**
* @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(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Profile.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 Profile().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField jAddress;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JTextField jCity;
private javax.swing.JTextArea jComments;
private javax.swing.JTextField jCountry;
private javax.swing.JTextField jFirstName;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel29;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel33;
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 jLabel9;
private javax.swing.JTextField jLastName;
private javax.swing.JTextField jMiddleName;
private javax.swing.JTextField jNationality;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel10;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JPanel jPanel9;
private javax.swing.JTextField jPhone;
private javax.swing.JTextField jPostCode;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}
</code>
<code>/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template */ package com.mycompany.mrms; import java.awt.Color; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.Types; import javax.swing.JOptionPane; /** * * @author patok */ public class Profile extends javax.swing.JFrame { /** * Creates new form Profile */ Color DefaultColor,ClickedColor; private static final String USRNM = "root"; private static final String PASWD = "admin"; private static final String DATA_BASE = "jdbc:mysql://localhost:3306/db_mrms"; private static final String DRIVER = "com.mysql.cj.jdbc.Driver"; Connection db_mrms = null; PreparedStatement ps = null; public Profile() { initComponents(); DefaultColor = new Color(4,59,92); ClickedColor = new Color(249,180,45); jPanel5.setBackground(DefaultColor); jPanel3.setBackground(ClickedColor); jPanel6.setBackground(DefaultColor); jPanel7.setBackground(DefaultColor); jPanel8.setBackground(DefaultColor); jPanel9.setBackground(DefaultColor); } /** * 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() { jPanel4 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jFirstName = new javax.swing.JTextField(); jMiddleName = new javax.swing.JTextField(); jLastName = new javax.swing.JTextField(); jPhone = new javax.swing.JTextField(); jNationality = new javax.swing.JTextField(); jCountry = new javax.swing.JTextField(); jCity = new javax.swing.JTextField(); jAddress = new javax.swing.JTextField(); jPostCode = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); jComments = new javax.swing.JTextArea(); jLabel8 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel33 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel29 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jPanel10 = new javax.swing.JPanel(); jLabel16 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jPanel5 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); jPanel6 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jPanel9 = new javax.swing.JPanel(); jLabel7 = new javax.swing.JLabel(); jPanel7 = new javax.swing.JPanel(); jLabel5 = new javax.swing.JLabel(); jPanel8 = new javax.swing.JPanel(); jLabel6 = new javax.swing.JLabel(); private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) { // TODO add your handling code here: } private void jLabel1MousePressed(java.awt.event.MouseEvent evt) { } private void jPanel5MouseEntered(java.awt.event.MouseEvent evt) { // TODO add your handling code here: jPanel5.setBackground(ClickedColor); jPanel3.setBackground(DefaultColor); jPanel6.setBackground(DefaultColor); jPanel7.setBackground(DefaultColor); jPanel8.setBackground(DefaultColor); jPanel9.setBackground(DefaultColor); } private void jPanel3MousePressed(java.awt.event.MouseEvent evt) { // TODO add your handling code here: jPanel5.setBackground(DefaultColor); jPanel3.setBackground(ClickedColor); jPanel6.setBackground(DefaultColor); jPanel7.setBackground(DefaultColor); jPanel8.setBackground(DefaultColor); jPanel9.setBackground(DefaultColor); } private void jPanel6MousePressed(java.awt.event.MouseEvent evt) { // TODO add your handling code here: jPanel5.setBackground(DefaultColor); jPanel3.setBackground(DefaultColor); jPanel6.setBackground(ClickedColor); jPanel7.setBackground(DefaultColor); jPanel8.setBackground(DefaultColor); jPanel9.setBackground(DefaultColor); } private void jPanel9MousePressed(java.awt.event.MouseEvent evt) { // TODO add your handling code here: jPanel5.setBackground(DefaultColor); jPanel3.setBackground(DefaultColor); jPanel6.setBackground(DefaultColor); jPanel7.setBackground(DefaultColor); jPanel8.setBackground(DefaultColor); jPanel9.setBackground(ClickedColor); } private void jPanel7MousePressed(java.awt.event.MouseEvent evt) { // TODO add your handling code here: jPanel5.setBackground(DefaultColor); jPanel3.setBackground(DefaultColor); jPanel6.setBackground(DefaultColor); jPanel7.setBackground(ClickedColor); jPanel8.setBackground(DefaultColor); jPanel9.setBackground(DefaultColor); } private void jPanel8MousePressed(java.awt.event.MouseEvent evt) { // TODO add your handling code here: jPanel5.setBackground(DefaultColor); jPanel3.setBackground(DefaultColor); jPanel6.setBackground(DefaultColor); jPanel7.setBackground(DefaultColor); jPanel8.setBackground(ClickedColor); jPanel9.setBackground(DefaultColor); } private void jPostCodeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String firstName = jFirstName.getText(); String middleName = jMiddleName.getText(); String lastName = jLastName.getText(); String phone = jPhone.getText(); String nationality = jNationality.getText(); String country = jCountry.getText(); String city = jCity.getText(); String address = jAddress.getText(); String postCode = jPostCode.getText(); String comments = jComments.getText(); if (middleName.equals("") && lastName.equals("") && phone.equals("") && nationality.equals("") && country.equals("") && city.equals("") && address.equals("") && postCode.equals("") && comments.equals("")) { JOptionPane.showMessageDialog(null, "To update information, please fill some information into the textfields."); } else { try { Class.forName(DRIVER); db_mrms = DriverManager.getConnection(DATA_BASE, USRNM, PASWD); String sql = "UPDATE patients SET "; boolean isFirst = true; if (!firstName.equals("")) { sql += "FirstName = IFNULL(?, FirstName), "; isFirst = false; } if (!middleName.equals("")) { sql += "MiddleName = ?, "; isFirst = false; } if (!lastName.equals("")) { sql += "LastName = ?, "; isFirst = false; } if (!phone.equals("")) { sql += "Phone = ?, "; isFirst = false; } if (!nationality.equals("")) { sql += "Nationality = ?, "; isFirst = false; } if (!country.equals("")) { sql += "Country = ?, "; isFirst = false; } if (!city.equals("")) { sql += "City = ?, "; isFirst = false; } if (!address.equals("")) { sql += "Address = ?, "; isFirst = false; } if (!postCode.equals("")) { sql += "PostCode = ?, "; isFirst = false; } if (!comments.equals("")) { sql += "Comments = ?, "; isFirst = false; } // Remove the trailing comma and space sql = sql.substring(0, sql.length() - 2); // Add the WHERE clause sql += " WHERE PatientID = ?"; // Add your WHERE clause here PreparedStatement ps = db_mrms.prepareStatement(sql); int parameterIndex = 1; if (!firstName.equals("")) { ps.setString(parameterIndex++, firstName); } if (!middleName.equals("")) { ps.setString(parameterIndex++, middleName); } if (!lastName.equals("")) { ps.setString(parameterIndex++, lastName); } if (!phone.equals("")) { ps.setString(parameterIndex++, phone); } if (!nationality.equals("")) { ps.setString(parameterIndex++, nationality); } if (!country.equals("")) { ps.setString(parameterIndex++, country); } if (!city.equals("")) { ps.setString(parameterIndex++, city); } if (!address.equals("")) { ps.setString(parameterIndex++, address); } if (!postCode.equals("")) { ps.setString(parameterIndex++, postCode); } if (!comments.equals("")) { ps.setString(parameterIndex++, comments); } int rowsAffected = ps.executeUpdate(); if (rowsAffected > 0) { JOptionPane.showMessageDialog(null, "User Information Updated Successfully!"); setVisible(false); new Profile().setVisible(true); } else { JOptionPane.showMessageDialog(null, "No changes were made."); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } /** * @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(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Profile.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 Profile().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JTextField jAddress; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JTextField jCity; private javax.swing.JTextArea jComments; private javax.swing.JTextField jCountry; private javax.swing.JTextField jFirstName; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel29; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel33; 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 jLabel9; private javax.swing.JTextField jLastName; private javax.swing.JTextField jMiddleName; private javax.swing.JTextField jNationality; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel10; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPanel jPanel8; private javax.swing.JPanel jPanel9; private javax.swing.JTextField jPhone; private javax.swing.JTextField jPostCode; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration } </code>
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
 */
package com.mycompany.mrms;

import java.awt.Color;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Types;
import javax.swing.JOptionPane;

/**
 *
 * @author patok
 */
public class Profile extends javax.swing.JFrame {

    /**
     * Creates new form Profile
     */
    Color DefaultColor,ClickedColor;
    
    private static final String USRNM = "root";
    private static final String PASWD = "admin";
    private static final String DATA_BASE = "jdbc:mysql://localhost:3306/db_mrms";
    private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    
    Connection db_mrms = null;
    PreparedStatement ps = null;
    
    
    public Profile() {
        initComponents();
        DefaultColor = new Color(4,59,92);
        ClickedColor = new Color(249,180,45);
        
        jPanel5.setBackground(DefaultColor);
        jPanel3.setBackground(ClickedColor);
        jPanel6.setBackground(DefaultColor);
        jPanel7.setBackground(DefaultColor);
        jPanel8.setBackground(DefaultColor);
        jPanel9.setBackground(DefaultColor);
    }
    

    /**
     * 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() {

        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jFirstName = new javax.swing.JTextField();
        jMiddleName = new javax.swing.JTextField();
        jLastName = new javax.swing.JTextField();
        jPhone = new javax.swing.JTextField();
        jNationality = new javax.swing.JTextField();
        jCountry = new javax.swing.JTextField();
        jCity = new javax.swing.JTextField();
        jAddress = new javax.swing.JTextField();
        jPostCode = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jComments = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();

        
    private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) {                                       
        // TODO add your handling code here:
    }                                      

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

    }                                    

    private void jPanel5MouseEntered(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        jPanel5.setBackground(ClickedColor);
        jPanel3.setBackground(DefaultColor);
        jPanel6.setBackground(DefaultColor);
        jPanel7.setBackground(DefaultColor);
        jPanel8.setBackground(DefaultColor);
        jPanel9.setBackground(DefaultColor);

    }                                    

    private void jPanel3MousePressed(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        jPanel5.setBackground(DefaultColor);
        jPanel3.setBackground(ClickedColor);
        jPanel6.setBackground(DefaultColor);
        jPanel7.setBackground(DefaultColor);
        jPanel8.setBackground(DefaultColor);
        jPanel9.setBackground(DefaultColor);

    }                                    

    private void jPanel6MousePressed(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        jPanel5.setBackground(DefaultColor);
        jPanel3.setBackground(DefaultColor);
        jPanel6.setBackground(ClickedColor);
        jPanel7.setBackground(DefaultColor);
        jPanel8.setBackground(DefaultColor);
        jPanel9.setBackground(DefaultColor);
    }                                    

    private void jPanel9MousePressed(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        jPanel5.setBackground(DefaultColor);
        jPanel3.setBackground(DefaultColor);
        jPanel6.setBackground(DefaultColor);
        jPanel7.setBackground(DefaultColor);
        jPanel8.setBackground(DefaultColor);
        jPanel9.setBackground(ClickedColor);
    }                                    

    private void jPanel7MousePressed(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        jPanel5.setBackground(DefaultColor);
        jPanel3.setBackground(DefaultColor);
        jPanel6.setBackground(DefaultColor);
        jPanel7.setBackground(ClickedColor);
        jPanel8.setBackground(DefaultColor);
        jPanel9.setBackground(DefaultColor);
    }                                    

    private void jPanel8MousePressed(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        jPanel5.setBackground(DefaultColor);
        jPanel3.setBackground(DefaultColor);
        jPanel6.setBackground(DefaultColor);
        jPanel7.setBackground(DefaultColor);
        jPanel8.setBackground(ClickedColor);
        jPanel9.setBackground(DefaultColor);
    }                                    

    private void jPostCodeActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
    }                                         

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  // TODO add your handling code here:
        String firstName = jFirstName.getText();
        String middleName = jMiddleName.getText();
        String lastName = jLastName.getText();
        String phone = jPhone.getText();
        String nationality = jNationality.getText();
        String country = jCountry.getText();
        String city = jCity.getText();
        String address = jAddress.getText();
        String postCode = jPostCode.getText();
        String comments = jComments.getText();

        if (middleName.equals("") && lastName.equals("") && phone.equals("") && nationality.equals("") && country.equals("") && city.equals("") && address.equals("") && postCode.equals("") && comments.equals("")) {
        JOptionPane.showMessageDialog(null, "To update information, please fill some information into the textfields.");
        } else {
            try {
        Class.forName(DRIVER);
        db_mrms = DriverManager.getConnection(DATA_BASE, USRNM, PASWD);
        String sql = "UPDATE patients SET ";
        boolean isFirst = true;

        if (!firstName.equals("")) { sql += "FirstName = IFNULL(?, FirstName), "; isFirst = false; }
        if (!middleName.equals("")) { sql += "MiddleName = ?, "; isFirst = false; }
        if (!lastName.equals("")) { sql += "LastName = ?, "; isFirst = false; }
        if (!phone.equals("")) { sql += "Phone = ?, "; isFirst = false; }
        if (!nationality.equals("")) { sql += "Nationality = ?, "; isFirst = false; }
        if (!country.equals("")) { sql += "Country = ?, "; isFirst = false; }
        if (!city.equals("")) { sql += "City = ?, "; isFirst = false; }
        if (!address.equals("")) { sql += "Address = ?, "; isFirst = false; }
        if (!postCode.equals("")) { sql += "PostCode = ?, "; isFirst = false; }
        if (!comments.equals("")) { sql += "Comments = ?, "; isFirst = false; }

        // Remove the trailing comma and space
        sql = sql.substring(0, sql.length() - 2);

        // Add the WHERE clause
        sql += " WHERE PatientID = ?"; // Add your WHERE clause here

        PreparedStatement ps = db_mrms.prepareStatement(sql);
        int parameterIndex = 1;

        if (!firstName.equals("")) { ps.setString(parameterIndex++, firstName); }
        if (!middleName.equals("")) { ps.setString(parameterIndex++, middleName); }
        if (!lastName.equals("")) { ps.setString(parameterIndex++, lastName); }
        if (!phone.equals("")) { ps.setString(parameterIndex++, phone); }
        if (!nationality.equals("")) { ps.setString(parameterIndex++, nationality); }
        if (!country.equals("")) { ps.setString(parameterIndex++, country); }
        if (!city.equals("")) { ps.setString(parameterIndex++, city); }
        if (!address.equals("")) { ps.setString(parameterIndex++, address); }
        if (!postCode.equals("")) { ps.setString(parameterIndex++, postCode); }
        if (!comments.equals("")) { ps.setString(parameterIndex++, comments); }

        int rowsAffected = ps.executeUpdate();
        if (rowsAffected > 0) {
            JOptionPane.showMessageDialog(null, "User Information Updated Successfully!");
            setVisible(false);
            new Profile().setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "No changes were made.");
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

        }


   
    }                                        

    /**
     * @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(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Profile.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Profile.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 Profile().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTextField jAddress;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JTextField jCity;
    private javax.swing.JTextArea jComments;
    private javax.swing.JTextField jCountry;
    private javax.swing.JTextField jFirstName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel33;
    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 jLabel9;
    private javax.swing.JTextField jLastName;
    private javax.swing.JTextField jMiddleName;
    private javax.swing.JTextField jNationality;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTextField jPhone;
    private javax.swing.JTextField jPostCode;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration                   
}

If you guys need the rest of the files I can provide them. Thank you in advance.

I tried different methods from ChatGPT lol, but nothing happened.

New contributor

Nikolay Mihaylov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật