Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------- Application.java ----------------------------------
- package appli;
- import bd.*;
- import bean.*;
- import java.sql.*;
- import dao.*;
- public class Application {
- public static void main(String[] args) throws SQLException {
- // TODO Auto-generated method stub
- SessionOracle connection = new SessionOracle("VOTRE ID DE CO", "MOT DE PASSE");
- connection.getConnection();
- DAOEmploye test = new DAOEmploye(connection);
- Employe testE1 = new Employe("Jean", 2500, 55, 3, 32);
- test.delete(testE1);
- }
- }
- ---------------------------------------------- Employe.java -------------------------------------
- package bean;
- public class Employe {
- private String employe;
- private int salaire;
- private int nuempl;
- private int affect;
- private int hebdo;
- public Employe(String employe, int salaire, int nuempl, int affect, int hebdo) {
- super();
- this.employe = employe;
- this.salaire = salaire;
- this.nuempl = nuempl;
- this.affect = affect;
- this.hebdo = hebdo;
- }
- public String getEmploye() {
- return employe;
- }
- public void setEmploye(String employe) {
- this.employe = employe;
- }
- public int getSalaire() {
- return salaire;
- }
- public void setSalaire(int salaire) {
- this.salaire = salaire;
- }
- public int getNuempl() {
- return nuempl;
- }
- public void setNuempl(int nuempl) {
- this.nuempl = nuempl;
- }
- public int getAffect() {
- return affect;
- }
- public void setAffect(int affect) {
- this.affect = affect;
- }
- public int getHebdo() {
- return hebdo;
- }
- public void setHebdo(int hebdo) {
- this.hebdo = hebdo;
- }
- }
- ------------------------------------- DAOEmploye.java -------------------------------------------------
- package dao;
- import bd.*;
- import bean.*;
- import java.sql.*;
- public class DAOEmploye {
- private SessionOracle s;
- private Statement stmt;
- public DAOEmploye(SessionOracle ss) throws SQLException
- {
- this.s = ss;
- this.stmt = s.getConnection().createStatement();
- }
- public void create(Employe e)
- {
- System.out.println("Insertion de la ligne dans la table ...");
- try {
- stmt.executeUpdate("INSERT INTO EMPLOYE2 VALUES(" + e.getNuempl() + ",'" + e.getEmploye() + "'," + e.getHebdo() + "," + e.getAffect() + "," + e.getSalaire() + ")");
- System.out.println("Insertion réussie !");
- } catch (SQLException e1) {
- System.out.println(e1);
- }
- }
- public void delete(Employe e)
- {
- System.out.println("Supression de la ligne de la table ...");
- try {
- String deleteTableEmploye = new String("DELETE FROM EMPLOYE2 WHERE nuempl=" + e.getNuempl());
- stmt.executeUpdate(deleteTableEmploye);
- System.out.println(deleteTableEmploye);
- System.out.println("Supression réussie !");
- } catch (SQLException e1) {
- System.out.println(e1);
- }
- }
- public void update(Employe e)
- {
- System.out.println("Mise à jour de l'employé ...");
- try {
- String updateTableEmploye = new String("UPDATE EMPLOYE2 SET nomempl=" + "'" + e.getEmploye() + "'" + ", hebdo=" + e.getHebdo() +", affect=" + e.getAffect() + ", salaire=" + e.getSalaire() + " WHERE nuempl=" + e.getNuempl());
- System.out.println(updateTableEmploye);
- stmt.executeUpdate(updateTableEmploye);
- System.out.println("Mise à jour réussie !");
- } catch (SQLException e1) {
- System.out.println(e1);
- }
- }
- public void read()
- {
- System.out.println("Lecture de la table EMPLOYE2 ...");
- try {
- String selectTableEmploye = new String("SELECT * FROM EMPLOYE2 ORDER BY 1");
- ResultSet res = stmt.executeQuery(selectTableEmploye);
- System.out.println("Lecture terminée !");
- while(res.next()) {
- int numEmpl = res.getInt(1);
- String nomEmpl = res.getString(2);
- int hebdoEmpl = res.getInt(3);
- int affectEmpl = res.getInt(4);
- int salaireEmpl = res.getInt(5);
- System.out.println(" nuempl" + " " + "nomempl" + " " + "hebdo" + " " + "affect" + " " + "salaire");
- System.out.println(" " + numEmpl + " " + nomEmpl + hebdoEmpl + " " + affectEmpl + " " + salaireEmpl);
- System.out.println("");
- }
- }
- catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- }
- --------------------------------------------------------- SessionOracle.java --------------------------------------
- package bd;
- import java.sql.*;
- public class SessionOracle {
- public Connection conn;
- public SessionOracle(String user, String passwd) {
- try {
- DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
- conn = DriverManager.getConnection("jdbc:oracle:thin:@soracle3.iut-nantes.univ-nantes.prive:1521:DB1",user , passwd);
- System.out.println("connexion réussi");
- }
- catch(SQLException e){
- System.out.println("connexion échouée");
- }
- }
- public Connection getConnection()
- {
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement