| 12
 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
 
 |  
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%Class.forName("oracle.jdbc.driver.OracleDriver");%>
<%@ page import="java.lang.Double" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ajouter Client</title>
</head>
<body>
<form name = "firstForm" action =""
	style = "width:50% ; margin:auto ; background-color:#c1d9fc ; padding-botton:15px;">
 
	<h2 style = "text-align:center; color:white; background-color:#6683b1;">Ajouter un nouveau client</h2>
	<p style = "text-align:center;">N° Client : <input type = "text" name = "codeclt" /> </p>
	<p style = "text-align:center;">N° Assurrance : <input type = "text" name = "numass" /> </p>
	<p style = "text-align:center;">Nom : <input type = "text" name = "nom" /> </p>
	<p style = "text-align:center;">Prénom : <input type = "text" name = "prenom" /> </p>
	<p style = "text-align:center;">Situation Matrimoniale : <input type = "text" name = "situamat" /> </p>
	<p style = "text-align:center;">Age Client : <input type = "text" name = "age" /> </p>
<p style = "text-align:center;">Salaire : <input type = "text" name = "salaire" /> </p>
	<p style = "text-align:center;">Nombre de personnes en charge : <input type = "text" name = "nbrepersch" /> </p>
<p style = "text-align:center; width:50% ; margin:auto ;">
	<input type = "submit" name = "Soumettre" /> </p>
</form>	
	<%
        Connection conn=null;
        PreparedStatement pst=null;
        int n=0;
        // connexion à la base des données
        try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
                try {
                        conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:miage2", "SYSTEM", "miage2");
                        System.out.println("Connexion établie !");
                } catch (SQLException e) {
                        System.out.println("Connexion non établie");
                        e.printStackTrace();
                }
        } catch (ClassNotFoundException e) {
                System.out.println("Driver de classe incompatible !");
                e.printStackTrace();
        }
        // recupération des données de la page web
        String codeClt=request.getParameter("codeclt");
        String numass=request.getParameter("numass");
        String nom=request.getParameter("nom");
        String prenom=request.getParameter("prenom");
        String situamat=request.getParameter("situamat");
        String age=request.getParameter("age");
             double salaire=java.lang.Double.valueOf(request.getParameter("salaire")).doubleValue();
        int nbrepersch=Integer.parseInt(request.getParameter("nbrepersch"));
// construction du client
        ecobank.Client cl=new ecobank.Client();
        cl.setCodeClt(codeClt);
        cl.setNumass(numass);
        cl.setNom(nom);
        cl.setPrenom(prenom);
        cl.setSituamat(situamat);
        cl.setAge(age);
             cl.setSalaire(salaire);
        cl.setNbrepersch(nbrepersch);
// requête SQL
        
        try {
              pst=conn.prepareStatement("INSERT INTO TBCLIENT VALUES(?,?,?,?,?,?,?,?)");
        pst.setString(1, cl.getCodeClt());
        pst.setString(2, cl.getNumass());
        pst.setString(3, cl.getNom());
        pst.setString(4, cl.getPrenom());
        pst.setString(5, cl.getSituamat());
        pst.setString(6, cl.getAge());
             pst.setDouble(13, cl.getSalaire());
        pst.setInt(14, cl.getNbrepersch());
             n=pst.executeUpdate();
        System.out.println(n +" ligne ajoutée");
        pst.close();
        conn.close();
        } catch (SQLException e) {e.printStackTrace();
        }
        %>
</body>
</html> | 
Partager