java.sql.SQLIntegrityConstraintViolationException: Column ‘prenom’ cannot be null

I’m new in Java programming so that’s why I’m here seeking your kind help stackoverflowers.

I have this problem which I could not find the solution on internet, I hope someone could inform me where is my mistake and how can I fix it.

My problem is that when I try to insert the data, everything goes fine, the window opens, I can insert the data, button looks just fine.

But it gives me this message

java.sql.SQLIntegrityConstraintViolationException: Column ‘prenom’ cannot be null

Which I assume was a problem with php mySQL, then I changed all variables to NULL, activating the button “Null” for all of them.

It then WORKED, but all informations were saved as “null” in my database, which didn’t really solve my problem.

My goal is to insert data (name, lastname, phone, email) into a data base (php mySQL) through eclipse. I did a program which I’m obliged to use window builder to insert that data, so graphical user interface MUST be used

What I expect to happen is to save data normally. Like, name = Mike, lastname = Tyson, phone = +55555, email = mtyson@gmail.com
And it shows in my database, not null message.

Thank you everyone

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>package interfaceGraphique;
import accesBaseDeDonnees.ClientsBDD;
import entites.Clients;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;
public class InterfaceClients extends JFrame {
static InterfaceClients window;
private JPanel contentPane;
private JTextField txtPrenom;
private JTextField txtNom;
private JTextField txtTelephone;
private JTextField txtEmail;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
InterfaceClients frame = new InterfaceClients();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public InterfaceClients() {
setBackground(new Color(0, 0, 0));
setOpacity(1.0f);
setTitle("Ajouter un client");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("Enregistrer");
btnNewButton.addActionListener(new ActionListener() {
private AbstractButton labelResult;
@Override
public void actionPerformed(ActionEvent e) {
String prenom = txtPrenom.getText();
String nom = txtNom.getText();
String telephone = txtTelephone.getText();
String email = txtEmail.getText();
Clients Clients = new Clients(prenom, nom, telephone, email);
ClientsBDD clientsBDD = new ClientsBDD();
Connection cn = clientsBDD.makeConnection();
clientsBDD.insert(Clients, cn);
clientsBDD.closeConnection(cn);
//labelResult = null;
//labelResult.setText("Client ajoute avec succes");
}
});
btnNewButton.setBounds(45, 227, 112, 23);
contentPane.add(btnNewButton);
txtPrenom = new JTextField();
txtPrenom.setBounds(124, 39, 258, 20);
contentPane.add(txtPrenom);
txtPrenom.setColumns(10);
txtNom = new JTextField();
txtNom.setColumns(10);
txtNom.setBounds(124, 82, 258, 20);
contentPane.add(txtNom);
txtTelephone = new JTextField();
txtTelephone.setColumns(10);
txtTelephone.setBounds(124, 125, 258, 20);
contentPane.add(txtTelephone);
txtEmail = new JTextField();
txtEmail.setColumns(10);
txtEmail.setBounds(124, 166, 258, 20);
contentPane.add(txtEmail);
JLabel lblNewLabel = new JLabel("Prenom");
lblNewLabel.setBounds(45, 42, 67, 14);
contentPane.add(lblNewLabel);
JLabel lblMarque = new JLabel("Nom");
lblMarque.setBounds(45, 85, 46, 14);
contentPane.add(lblMarque);
JLabel lblNewLabel_1_1 = new JLabel("Telephone");
lblNewLabel_1_1.setBounds(45, 128, 67, 14);
contentPane.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_1_1 = new JLabel("Email");
lblNewLabel_1_1_1.setBounds(45, 169, 89, 14);
contentPane.add(lblNewLabel_1_1_1);
JLabel labelResult = new JLabel("");
labelResult.setBounds(194, 229, 227, 16);
contentPane.add(labelResult);
}
}
</code>
<code>package interfaceGraphique; import accesBaseDeDonnees.ClientsBDD; import entites.Clients; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.AbstractButton; import javax.swing.JButton; import java.awt.event.ActionListener; import java.sql.Connection; import java.awt.event.ActionEvent; import javax.swing.JTextField; import javax.swing.JLabel; import java.awt.Color; public class InterfaceClients extends JFrame { static InterfaceClients window; private JPanel contentPane; private JTextField txtPrenom; private JTextField txtNom; private JTextField txtTelephone; private JTextField txtEmail; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { InterfaceClients frame = new InterfaceClients(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public InterfaceClients() { setBackground(new Color(0, 0, 0)); setOpacity(1.0f); setTitle("Ajouter un client"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JButton btnNewButton = new JButton("Enregistrer"); btnNewButton.addActionListener(new ActionListener() { private AbstractButton labelResult; @Override public void actionPerformed(ActionEvent e) { String prenom = txtPrenom.getText(); String nom = txtNom.getText(); String telephone = txtTelephone.getText(); String email = txtEmail.getText(); Clients Clients = new Clients(prenom, nom, telephone, email); ClientsBDD clientsBDD = new ClientsBDD(); Connection cn = clientsBDD.makeConnection(); clientsBDD.insert(Clients, cn); clientsBDD.closeConnection(cn); //labelResult = null; //labelResult.setText("Client ajoute avec succes"); } }); btnNewButton.setBounds(45, 227, 112, 23); contentPane.add(btnNewButton); txtPrenom = new JTextField(); txtPrenom.setBounds(124, 39, 258, 20); contentPane.add(txtPrenom); txtPrenom.setColumns(10); txtNom = new JTextField(); txtNom.setColumns(10); txtNom.setBounds(124, 82, 258, 20); contentPane.add(txtNom); txtTelephone = new JTextField(); txtTelephone.setColumns(10); txtTelephone.setBounds(124, 125, 258, 20); contentPane.add(txtTelephone); txtEmail = new JTextField(); txtEmail.setColumns(10); txtEmail.setBounds(124, 166, 258, 20); contentPane.add(txtEmail); JLabel lblNewLabel = new JLabel("Prenom"); lblNewLabel.setBounds(45, 42, 67, 14); contentPane.add(lblNewLabel); JLabel lblMarque = new JLabel("Nom"); lblMarque.setBounds(45, 85, 46, 14); contentPane.add(lblMarque); JLabel lblNewLabel_1_1 = new JLabel("Telephone"); lblNewLabel_1_1.setBounds(45, 128, 67, 14); contentPane.add(lblNewLabel_1_1); JLabel lblNewLabel_1_1_1 = new JLabel("Email"); lblNewLabel_1_1_1.setBounds(45, 169, 89, 14); contentPane.add(lblNewLabel_1_1_1); JLabel labelResult = new JLabel(""); labelResult.setBounds(194, 229, 227, 16); contentPane.add(labelResult); } } </code>
package interfaceGraphique;


import accesBaseDeDonnees.ClientsBDD;
import entites.Clients;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;

public class InterfaceClients extends JFrame {

    static InterfaceClients window;
    
    private JPanel contentPane;
    private JTextField txtPrenom;
    private JTextField txtNom;
    private JTextField txtTelephone;
    private JTextField txtEmail;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    InterfaceClients frame = new InterfaceClients();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public InterfaceClients() {
        setBackground(new Color(0, 0, 0));
        setOpacity(1.0f);
        setTitle("Ajouter un client");
        
        
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

        setContentPane(contentPane);
        contentPane.setLayout(null);
        
        JButton btnNewButton = new JButton("Enregistrer");
        btnNewButton.addActionListener(new ActionListener() {
            private AbstractButton labelResult;
            
            @Override
            public void actionPerformed(ActionEvent e) {
                String prenom = txtPrenom.getText();
                String nom = txtNom.getText();
                String telephone = txtTelephone.getText();
                String email = txtEmail.getText();
                
                Clients Clients = new Clients(prenom, nom, telephone, email);
                ClientsBDD clientsBDD = new ClientsBDD();
                Connection cn = clientsBDD.makeConnection();
                clientsBDD.insert(Clients, cn);
                clientsBDD.closeConnection(cn);
                
                //labelResult = null;
                //labelResult.setText("Client ajoute avec succes");
                }
        });
        btnNewButton.setBounds(45, 227, 112, 23);
        contentPane.add(btnNewButton);
        
        txtPrenom = new JTextField();
        txtPrenom.setBounds(124, 39, 258, 20);
        contentPane.add(txtPrenom);
        txtPrenom.setColumns(10);
        
        txtNom = new JTextField();
        txtNom.setColumns(10);
        txtNom.setBounds(124, 82, 258, 20);
        contentPane.add(txtNom);
        
        txtTelephone = new JTextField();
        txtTelephone.setColumns(10);
        txtTelephone.setBounds(124, 125, 258, 20);
        contentPane.add(txtTelephone);
        
        txtEmail = new JTextField();
        txtEmail.setColumns(10);
        txtEmail.setBounds(124, 166, 258, 20);
        contentPane.add(txtEmail);
        
        JLabel lblNewLabel = new JLabel("Prenom");
        lblNewLabel.setBounds(45, 42, 67, 14);
        contentPane.add(lblNewLabel);
        
        JLabel lblMarque = new JLabel("Nom");
        lblMarque.setBounds(45, 85, 46, 14);
        contentPane.add(lblMarque);
        
        JLabel lblNewLabel_1_1 = new JLabel("Telephone");
        lblNewLabel_1_1.setBounds(45, 128, 67, 14);
        contentPane.add(lblNewLabel_1_1);
        
        JLabel lblNewLabel_1_1_1 = new JLabel("Email");
        lblNewLabel_1_1_1.setBounds(45, 169, 89, 14);
        contentPane.add(lblNewLabel_1_1_1);
        
        JLabel labelResult = new JLabel("");
        labelResult.setBounds(194, 229, 227, 16);
        contentPane.add(labelResult);
    }
}

New contributor

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

1

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