1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
   |  
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
 
public class inscription extends JFrame {
 
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	Connection con;
	PreparedStatement state;
	ResultSet res;
 
	/**
         * Launch the application.
         */
	public static void main(String[] args) {
 
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					inscription frame = new inscription("org.postgresql.Driver","jdbc:postgresql://localhost:5432/table","postgres","password");
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
         * Create the frame.
         */
	public inscription(String drive,String url,String utilisateur,String pass) {
		try{
		Class.forName(drive);
		System.out.println("driver Ok");
		con=DriverManager.getConnection(url,utilisateur, pass);
		String s="INSERT INTO tablee VALUES(?,?,?);";
		 state=con.prepareStatement(s);
		System.out.println("connection etablie");
		}
		catch(Exception e){System.out.println(e.getMessage());}
		setTitle("Inscription");
		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);
 
		JLabel lblNom = new JLabel("Nom");
		lblNom.setBounds(36, 29, 46, 14);
		contentPane.add(lblNom);
 
		textField = new JTextField();
		textField.setBounds(156, 26, 175, 20);
		contentPane.add(textField);
		textField.setColumns(10);
 
		JLabel lblPrnom = new JLabel("Pr\u00E9nom");
		lblPrnom.setBounds(36, 66, 61, 14);
		contentPane.add(lblPrnom);
 
		textField_1 = new JTextField();
		textField_1.setBounds(156, 57, 175, 20);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
 
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setBounds(36, 103, 61, 14);
		contentPane.add(lblEmail);
 
		textField_2 = new JTextField();
		textField_2.setBounds(156, 100, 175, 20);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
 
		JButton btnSinscrire = new JButton("S'inscrire");
		btnSinscrire.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try{
				state.setString(1,textField.getText());
				state.setString(2,textField_1.getText());
				state.setString(3,textField_2.getText());
				state.executeUpdate();
				System.out.println("operation effectue avec succes");
				}
			catch(Exception a){System.out.println(a.getMessage());
				}
			}
		});
 
		btnSinscrire.setBounds(146, 146, 89, 23);
		contentPane.add(btnSinscrire);
 
		JButton btnAffichierListe = new JButton("Affichier Liste");
		btnAffichierListe.setBounds(146, 195, 122, 23);
		contentPane.add(btnAffichierListe);
	}
 
 
} | 
Partager