0% found this document useful (0 votes)
9 views11 pages

Ajout Modif

Uploaded by

Berlado Ber
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Ajout Modif

Uploaded by

Berlado Ber
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Ajout

/*

* 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.

*/

/**

* @author pc

*/

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class ajout extends JFrame implements ActionListener{

Container con=null;

JLabel l1 = new JLabel ("Matricule");

JTextField t1 = new JTextField(5);

JLabel l2 = new JLabel ("Nom");

JTextField t2 = new JTextField(25);

JLabel l3 = new JLabel ("M.generale");

JTextField t3 = new JTextField(12);


JButton b1 = new JButton("Insertion");

JButton b2 = new JButton("Quitter");

public ajout()

con=getContentPane();

con.setLayout(new FlowLayout());

setSize(new Dimension(1200,1000));

con.add(l1);

con.add(t1);

con.add(l2);

con.add(t2);

con.add(l3);

con.add(t3);

con.add(b1);

con.add(b2);

b1.addActionListener(this);

b2.addActionListener(this);

public void actionPerformed(ActionEvent toto)

if (toto.getSource()==b2)

JOptionPane.showMessageDialog(null,"bye have a good day see you next season ???");


System.exit(0);

else

//les etapes de connexion

try

//chargement pilote

Class.forName("oracle.jdbc.driver.OracleDriver");

//URl le chemin

Connection co=null;

co=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","marah");

//creation espace memoire pour exection de la requete

Statement s1 = co.createStatement();

Statement s2 = co.createStatement();

//declaration de la requete

String req="insert into etudiant values("+t1.getText()+",'"+t2.getText()+"',"+t3.getText()+")";

//execution de la requete

String req2="select * from etudiant where mat="+t1.getText();

ResultSet r = s2.executeQuery(req2);

int existe=0;

while(r.next())

existe=1;

if (existe==1)

{
JOptionPane.showMessageDialog(null,"Matricule existe deja ???");

else

int res=s1.executeUpdate(req);

JOptionPane.showMessageDialog(null,"insertion okkkkkkkkkkkkkk");

t1.setText("");

t2.setText("");

t3.setText("");

catch(ClassNotFoundException e1)

JOptionPane.showMessageDialog(null,"err de pilote");

catch(SQLException e2)

JOptionPane.showMessageDialog(null,"err de connexion ou err de requete");

public static void main(String[] arg)

new ajout().setVisible(true);

}
Modification

/*

* 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.

*/

/**

* @author pc

*/

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class modif extends JFrame implements ActionListener{

Container con=null;

JLabel l1 = new JLabel ("Matricule");

JComboBox com = new JComboBox();

JLabel l2 = new JLabel ("Nom");

JTextField t2 = new JTextField(25);

JLabel l3 = new JLabel ("M.generale");


JTextField t3 = new JTextField(12);

JButton b1 = new JButton("Modification");

JButton b2 = new JButton("Quitter");

public modif()

//remplissage de liste deroulante

try

//chargement pilote

Class.forName("oracle.jdbc.driver.OracleDriver");

//URl le chemin

Connection co=null;

co=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","marah");

//creation espace memoire pour exection de la requete

Statement s2 = co.createStatement();

//declaration de la requete

//execution de la requete

String req2="select * from etudiant";

ResultSet r = s2.executeQuery(req2);

while(r.next())

com.addItem(r.getInt("mat"));
}

catch(ClassNotFoundException e1)

JOptionPane.showMessageDialog(null,"err de pilote");

catch(SQLException e2)

JOptionPane.showMessageDialog(null,"err de connexion ou err de requete");

con=getContentPane();

con.setLayout(new FlowLayout());

setSize(new Dimension(1200,1000));

con.add(l1);

con.add(com);

con.add(l2);

con.add(t2);

con.add(l3);

con.add(t3);

con.add(b1);

con.add(b2);
b1.addActionListener(this);

b2.addActionListener(this);

com.addActionListener(this);

public void actionPerformed(ActionEvent toto)

if (toto.getSource()==b2)

JOptionPane.showMessageDialog(null,"bye have a good day see you next season ???");

System.exit(0);

else if (toto.getSource()==b1)

//les etapes de connexion

try

//chargement pilote

Class.forName("oracle.jdbc.driver.OracleDriver");

//URl le chemin

Connection co=null;

co=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","marah");

//creation espace memoire pour exection de la requete

Statement s1 = co.createStatement();
//declaration de la requete

String req="update etudiant set no='"+t2.getText()+"',mg="+t3.getText()+" where


mat="+com.getSelectedItem();

//execution de la requete

int res=s1.executeUpdate(req);

JOptionPane.showMessageDialog(null,"Modification is okkkkkkkkkkkkkkkkk");

catch(ClassNotFoundException e1)

JOptionPane.showMessageDialog(null,"err de pilote");

catch(SQLException e2)

JOptionPane.showMessageDialog(null,"err de connexion ou err de requete");

else

//affichage le nom + m.generale

try

//chargement pilote

Class.forName("oracle.jdbc.driver.OracleDriver");

//URl le chemin

Connection co=null;

co=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","marah");
//creation espace memoire pour exection de la requete

Statement s2 = co.createStatement();

//declaration de la requete

//execution de la requete

String req2="select * from etudiant where mat="+com.getSelectedItem();

ResultSet r = s2.executeQuery(req2);

while(r.next())

t2.setText(r.getString("no"));

t3.setText(r.getString("mg"));

catch(ClassNotFoundException e1)

JOptionPane.showMessageDialog(null,"err de pilote");

catch(SQLException e2)

JOptionPane.showMessageDialog(null,"err de connexion ou err de requete");

public static void main(String[] arg)


{

new modif().setVisible(true);

You might also like