Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.java.bd;
- import java.sql.*;
- import java.util.ArrayList;
- import java.util.List;
- import com.java.classe.Ecole;
- public class EcoleBD {
- public static Connection getConnection(){
- Connection con=null;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- con=DriverManager.getConnection("jdbc:mysql://localhost:3306/soufiane","root","");
- }catch(Exception e){System.out.println(e);}
- return con;
- }
- public static int save(Ecole u){
- int status=0;
- try{
- Connection con=getConnection();
- PreparedStatement ps=con.prepareStatement(
- "insert into ecole(nom_ecole, adresse_ecole) values(?,?)");
- ps.setString(1,u.getNom_ecole());
- ps.setString(2,u.getAdresse_ecole());
- status=ps.executeUpdate();
- }catch(Exception e){System.out.println(e);}
- return status;
- }
- public static List<Ecole> getAllRecords(){
- List<Ecole> list=new ArrayList<Ecole>();
- try{
- Connection con=getConnection();
- PreparedStatement ps=con.prepareStatement("select * from ecole");
- PreparedStatement sp=con.prepareStatement("select * from eleve");
- ResultSet rs=ps.executeQuery();
- ResultSet sr=sp.executeQuery();
- while(rs.next()){
- Ecole u=new Ecole();
- u.setPk_ecole(rs.getInt("pk_ecole"));
- u.setNom_ecole(rs.getString("nom_ecole"));
- u.setAdresse_ecole(rs.getString("adresse_ecole"));
- list.add(u);
- }
- }catch(Exception e){System.out.println(e);}
- return list;
- }
- public static Ecole getRecordById(int pk_ecole){
- Ecole u=null;
- try{
- Connection con=getConnection();
- PreparedStatement ps=con.prepareStatement("select * from ecole where pk_ecole=?");
- ps.setInt(1,pk_ecole);
- ResultSet rs=ps.executeQuery();
- while(rs.next()){
- u=new Ecole();
- u.setPk_ecole(rs.getInt("pk_ecole"));
- u.setNom_ecole(rs.getString("nom_ecole"));
- u.setAdresse_ecole(rs.getString("adresse_ecole"));
- }
- }catch(Exception e){System.out.println(e);}
- return u;
- }
- public static int lol(Eleve u){
- int status=0;
- try{
- Connection con=getConnection();
- PreparedStatement ps=con.prepareStatement(
- "insert into eleve(nom_eleve, prenom_eleve, naissance_eleve, fk_ecole) values(?,?,?,?)");
- ps.setString(1,u.getNom_eleve());
- ps.setString(2,u.getPrenom_eleve());
- ps.setString(3,u.getNaissance_eleve());
- ps.setInt(4,u.getFk_ecole());
- status=ps.executeUpdate();
- }catch(Exception e){System.out.println(e);}
- return status;
- }
- }
Add Comment
Please, Sign In to add comment