Vous êtes sur la page 1sur 3

package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
//import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import utilisateures.user;

public class implementationuser implements daouser {


//------------------>>m�thode1:

@Override
public user ajouter(user u) {
Connection conn=SingletonCnnection.getCon();
try {
PreparedStatement ps=conn.prepareStatement("insert into
user(cne, nom, prenom, adresse, login, passworde) VALUES (?,?,?,?,?,?)");
ps.setString(1, u.getCne());
ps.setString(2,u.getNom() );
ps.setString(3, u.getPrenom());
ps.setString(4, u.getAdresse());
ps.setString(5, u.getLogin());
ps.setString(6, u.getPassworde());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
return u;
}

//------------------->>m�thode2:

@Override public List<user> users( String MC) {


List<user> ls =new ArrayList<user>();
Connection conn=SingletonCnnection.getCon();
try {
PreparedStatement ps=conn.prepareStatement("SELECT * FROM user where prenom
like ?");
ps.setString(1, MC);
ResultSet rs=ps.executeQuery();
while(rs.next()) {
user u = new user();
u.setCne(rs.getString("cne"));
u.setNom(rs.getString("nom"));
u.setPrenom(rs.getString("prenom"));
u.setAdresse(rs.getString("adresse"));
u.setLogin(rs.getString("login"));
u.setPassworde(rs.getString("passworde"));
ls.add(u);
} } catch (SQLException e) {
e.printStackTrace(); } return ls; }

//------------------->>m�thode3:
@Override public user rechercher(String cne) {
user u=null;
Connection conn=SingletonCnnection.getCon();
try {
PreparedStatement ps=conn.prepareStatement("SELECT * FROM user where
cne=?");
ps.setString(1, cne);
ResultSet rs=ps.executeQuery();
if(rs.next()) {
u = new user();
u.setCne(rs.getString("cne"));
u.setNom(rs.getString("nom"));
u.setPrenom(rs.getString("prenom"));
u.setAdresse(rs.getString("adresse"));
u.setLogin(rs.getString("login"));
u.setPassworde(rs.getString("passworde"));
} } catch (SQLException e) {
e.printStackTrace(); } return u; }

//------------------->>m�thode4:
@Override public user modifier(user u) {
Connection conn=SingletonCnnection.getCon();
try {
PreparedStatement ps=conn.prepareStatement("update
user set nom=?, prenom=?, adresse=?, login=?, passworde=? where cne=?");

ps.setString(1,u.getNom() );
ps.setString(2, u.getPrenom());
ps.setString(3, u.getAdresse());
ps.setString(4, u.getLogin());
ps.setString(5, u.getPassworde());
ps.setString(6, u.getCne());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
return u;
}

//------------------->>m�thode5:
@Override public void supprimer(String cne) {
Connection conn=SingletonCnnection.getCon();
try {
PreparedStatement ps=conn.prepareStatement("delete from
user where cne=?");
ps.setString(1, cne);
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}