IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

Insertio en modele DAO dans une base Oracle


Sujet :

Servlets/JSP Java

  1. #1
    Nouveau candidat au Club
    Inscrit en
    Janvier 2011
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Janvier 2011
    Messages : 1
    Par défaut Insertio en modele DAO dans une base Oracle
    Bonjour

    J'ai crée une application utilisant le design pattern DAO et DTO en code J2EE et pages JSP ou je me dois d'insérer des données, les modifier,les supprimer et de les récuperer .
    Pour la récuperation c ok! sauf que pour les autres j'ai tjrs un souci voici mon code

    ClientDAO

    package com.mycompany.loca.dao;

    import com.mycompany.loca.dto.*;
    import com.mycompany.loca.exceptions.*;

    public interface ClientDao
    {
    /**
    * Inserts a new row in the CLIENT table.
    */
    public void insert (ClientPk pk,Client dto) throws ClientDaoException;

    /**
    * Updates a single row in the CLIENT table.
    */
    public void update(ClientPk pk, Client dto) throws ClientDaoException;

    /**
    * Deletes a single row in the CLIENT table.
    */
    public void delete(ClientPk pk) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria ''.
    */
    public Client[] findAll() throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria 'NUMEROCLIENT = :numeroclient'.
    */
    public Client[] findWhereNumeroclientEquals(String numeroclient) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria 'NOM = :nom'.
    */
    public Client[] findWhereNomEquals(String nom) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria 'NATIONALITÉ = :nationalité'.
    */
    public Client[] findWhereNationalitéEquals(String nationalité) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria 'PASSEPORT = :passeport'.
    */
    public Client[] findWherePasseportEquals(String passeport) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria 'PERMIS = :permis'.
    */
    public Client[] findWherePermisEquals(String permis) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria 'TELEPHONE = :telephone'.
    */
    public Client[] findWhereTelephoneEquals(String telephone) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the criteria 'MAIL = :mail'.
    */
    public Client[] findWhereMailEquals(String mail) throws ClientDaoException;

    /**
    * Sets the value of maxRows
    */
    public void setMaxRows(int maxRows);

    /**
    * Gets the value of maxRows
    */
    public int getMaxRows();

    /**
    * Returns all rows from the CLIENT table that match the specified arbitrary SQL statement
    */
    public Client[] findByDynamicSelect(String sql, Object[] sqlParams) throws ClientDaoException;

    /**
    * Returns all rows from the CLIENT table that match the specified arbitrary SQL statement
    */
    public Client[] findByDynamicWhere(String sql, Object[] sqlParams) throws ClientDaoException;

    }
    ClientDAOimpl
    /*
    * This source file was generated by FireStorm/DAO.
    *
    * If you purchase a full license for FireStorm/DAO you can customize this header file.
    *
    * For more information please visit http://www.codefutures.com/products/firestorm
    */

    package com.mycompany.loca.jdbc;

    import com.mycompany.loca.dao.*;
    import com.mycompany.loca.dto.*;
    import com.mycompany.loca.exceptions.*;

    import java.sql.Connection;
    import java.util.Collection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;

    public class ClientDaoImpl extends AbstractDAO implements ClientDao
    {
    /**
    * The factory class for this DAO has two versions of the create() method - one that
    takes no arguments and one that takes a Connection argument. If the Connection version
    is chosen then the connection will be stored in this attribute and will be used by all
    calls to this DAO, otherwise a new Connection will be allocated for each operation.
    */
    protected java.sql.Connection userConn;

    /**
    * All finder methods in this class use this SELECT constant to build their queries
    */
    protected final String SQL_SELECT = "SELECT NUMEROCLIENT, NOM, PRENOM, ADRESSE, NATIONALITÉ, PASSEPORT, PERMIS, TELEPHONE, MAIL, NOMAC, PRENOMAC, ADRESSEAC, NATIONALITÉAC, PASSEPORTAC, PERMISAC, TELEPHONEAC, MAILAC FROM " + getTableName() + "";

    /**
    * Finder methods will pass this value to the JDBC setMaxRows method
    */
    protected int maxRows;

    /**
    * SQL INSERT statement for this table
    */
    protected final String SQL_INSERT = "INSERT INTO " + getTableName() + " ( NUMEROCLIENT, NOM, PRENOM, ADRESSE, NATIONALITÉ, PASSEPORT, PERMIS, TELEPHONE, MAIL, NOMAC, PRENOMAC, ADRESSEAC, NATIONALITÉAC, PASSEPORTAC, PERMISAC, TELEPHONEAC, MAILAC ) VALUES ( ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";

    /**
    * SQL UPDATE statement for this table
    */
    protected final String SQL_UPDATE = "UPDATE " + getTableName() + " SET NUMEROCLIENT = ?, NOM = ?, PRENOM = ?, ADRESSE = ?, NATIONALITÉ = ?, PASSEPORT = ?, PERMIS = ?, TELEPHONE = ?, MAIL = ?, NOMAC = ?, PRENOMAC = ?, ADRESSEAC = ?, NATIONALITÉAC = ?, PASSEPORTAC = ?, PERMISAC = ?, TELEPHONEAC = ?, MAILAC = ? WHERE NUMEROCLIENT = ?";

    /**
    * SQL DELETE statement for this table
    */
    protected final String SQL_DELETE = "DELETE FROM " + getTableName() + " WHERE NUMEROCLIENT = ?";

    /**
    * Index of column NUMEROCLIENT
    */
    protected static final int COLUMN_NUMEROCLIENT = 1;

    /**
    * Index of column NOM
    */
    protected static final int COLUMN_NOM = 2;

    /**
    * Index of column PRENOM
    */
    protected static final int COLUMN_PRENOM = 3;

    /**
    * Index of column ADRESSE
    */
    protected static final int COLUMN_ADRESSE = 4;

    /**
    * Index of column NATIONALITÉ
    */
    protected static final int COLUMN_NATIONALITÉ = 5;

    /**
    * Index of column PASSEPORT
    */
    protected static final int COLUMN_PASSEPORT = 6;

    /**
    * Index of column PERMIS
    */
    protected static final int COLUMN_PERMIS = 7;

    /**
    * Index of column TELEPHONE
    */
    protected static final int COLUMN_TELEPHONE = 8;

    /**
    * Index of column MAIL
    */
    protected static final int COLUMN_MAIL = 9;

    /**
    * Index of column NOMAC
    */
    protected static final int COLUMN_NOMAC = 10;

    /**
    * Index of column PRENOMAC
    */
    protected static final int COLUMN_PRENOMAC = 11;

    /**
    * Index of column ADRESSEAC
    */
    protected static final int COLUMN_ADRESSEAC = 12;

    /**
    * Index of column NATIONALITÉAC
    */
    protected static final int COLUMN_NATIONALITÉAC = 13;

    /**
    * Index of column PASSEPORTAC
    */
    protected static final int COLUMN_PASSEPORTAC = 14;

    /**
    * Index of column PERMISAC
    */
    protected static final int COLUMN_PERMISAC = 15;

    /**
    * Index of column TELEPHONEAC
    */
    protected static final int COLUMN_TELEPHONEAC = 16;

    /**
    * Index of column MAILAC
    */
    protected static final int COLUMN_MAILAC = 17;

    /**
    * Number of columns
    */
    protected static final int NUMBER_OF_COLUMNS = 17;

    /**
    * Index of primary-key column NUMEROCLIENT
    */
    protected static final int PK_COLUMN_NUMEROCLIENT = 1;

    /**
    * Inserts a new row in the CLIENT table.
    */
    public ClientPk insert(Client dto) throws ClientDaoException
    {
    long t1 = System.currentTimeMillis();
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;
    @SuppressWarnings("unused")
    ResultSet rs = null;

    try {
    // get the user-specified connection or get a connection from the ResourceManager
    conn = isConnSupplied ? userConn : ResourceManager.getConnection();

    StringBuffer sql = new StringBuffer();
    StringBuffer values = new StringBuffer();
    sql.append( "INSERT INTO " + getTableName() + " (" );
    int modifiedCount = 0;
    if (dto.isNumeroclientModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "NUMEROCLIENT" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isNomModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "NOM" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isPrenomModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "PRENOM" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isAdresseModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "ADRESSE" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isNationalitéModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "NATIONALITÉ" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isPasseportModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "PASSEPORT" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isPermisModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "PERMIS" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isTelephoneModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "TELEPHONE" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isMailModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "MAIL" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isNomacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "NOMAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isPrenomacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "PRENOMAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isAdresseacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "ADRESSEAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isNationalitéacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "NATIONALITÉAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isPasseportacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "PASSEPORTAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isPermisacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "PERMISAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isTelephoneacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "TELEPHONEAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (dto.isMailacModified()) {
    if (modifiedCount>0) {
    sql.append( ", " );
    values.append( ", " );
    }

    sql.append( "MAILAC" );
    values.append( "?" );
    modifiedCount++;
    }

    if (modifiedCount==0) {
    // nothing to insert
    throw new IllegalStateException( "Nothing to insert" );
    }

    sql.append( ") VALUES (" );
    sql.append( values );
    sql.append( ")" );
    stmt = conn.prepareStatement( sql.toString() );
    int index = 1;
    if (dto.isNumeroclientModified()) {
    stmt.setString( index++, dto.getNumeroclient() );
    }

    if (dto.isNomModified()) {
    stmt.setString( index++, dto.getNom() );
    }

    if (dto.isPrenomModified()) {
    stmt.setString( index++, dto.getPrenom() );
    }

    if (dto.isAdresseModified()) {
    stmt.setString( index++, dto.getAdresse() );
    }

    if (dto.isNationalitéModified()) {
    stmt.setString( index++, dto.getNationalité() );
    }

    if (dto.isPasseportModified()) {
    stmt.setString( index++, dto.getPasseport() );
    }

    if (dto.isPermisModified()) {
    stmt.setString( index++, dto.getPermis() );
    }

    if (dto.isTelephoneModified()) {
    stmt.setString( index++, dto.getTelephone() );
    }

    if (dto.isMailModified()) {
    stmt.setString( index++, dto.getMail() );
    }

    if (dto.isNomacModified()) {
    stmt.setString( index++, dto.getNomac() );
    }

    if (dto.isPrenomacModified()) {
    stmt.setString( index++, dto.getPrenomac() );
    }

    if (dto.isAdresseacModified()) {
    stmt.setString( index++, dto.getAdresseac() );
    }

    if (dto.isNationalitéacModified()) {
    stmt.setString( index++, dto.getNationalitéac() );
    }

    if (dto.isPasseportacModified()) {
    stmt.setString( index++, dto.getPasseportac() );
    }

    if (dto.isPermisacModified()) {
    stmt.setString( index++, dto.getPermisac() );
    }

    if (dto.isTelephoneacModified()) {
    stmt.setString( index++, dto.getTelephoneac() );
    }

    if (dto.isMailacModified()) {
    stmt.setString( index++, dto.getMailac() );
    }

    System.out.println( "Executing " + sql.toString() + " with values: " + dto );
    int rows = stmt.executeUpdate();
    long t2 = System.currentTimeMillis();
    System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
    reset(dto);
    return dto.createPk();
    }
    catch (Exception _e) {
    _e.printStackTrace();
    throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
    }
    finally {
    ResourceManager.close(stmt);
    if (!isConnSupplied) {
    ResourceManager.close(conn);
    }

    }

    }

    /**
    * Updates a single row in the CLIENT table.
    */
    public void update(ClientPk pk, Client dto) throws ClientDaoException
    {
    long t1 = System.currentTimeMillis();
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;

    try {
    // get the user-specified connection or get a connection from the ResourceManager
    conn = isConnSupplied ? userConn : ResourceManager.getConnection();

    StringBuffer sql = new StringBuffer();
    sql.append( "UPDATE " + getTableName() + " SET " );
    boolean modified = false;
    if (dto.isNumeroclientModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "NUMEROCLIENT=?" );
    modified=true;
    }

    if (dto.isNomModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "NOM=?" );
    modified=true;
    }

    if (dto.isPrenomModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "PRENOM=?" );
    modified=true;
    }

    if (dto.isAdresseModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "ADRESSE=?" );
    modified=true;
    }

    if (dto.isNationalitéModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "NATIONALITÉ=?" );
    modified=true;
    }

    if (dto.isPasseportModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "PASSEPORT=?" );
    modified=true;
    }

    if (dto.isPermisModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "PERMIS=?" );
    modified=true;
    }

    if (dto.isTelephoneModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "TELEPHONE=?" );
    modified=true;
    }

    if (dto.isMailModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "MAIL=?" );
    modified=true;
    }

    if (dto.isNomacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "NOMAC=?" );
    modified=true;
    }

    if (dto.isPrenomacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "PRENOMAC=?" );
    modified=true;
    }

    if (dto.isAdresseacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "ADRESSEAC=?" );
    modified=true;
    }

    if (dto.isNationalitéacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "NATIONALITÉAC=?" );
    modified=true;
    }

    if (dto.isPasseportacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "PASSEPORTAC=?" );
    modified=true;
    }

    if (dto.isPermisacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "PERMISAC=?" );
    modified=true;
    }

    if (dto.isTelephoneacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "TELEPHONEAC=?" );
    modified=true;
    }

    if (dto.isMailacModified()) {
    if (modified) {
    sql.append( ", " );
    }

    sql.append( "MAILAC=?" );
    modified=true;
    }

    if (!modified) {
    // nothing to update
    return;
    }

    sql.append( " WHERE NUMEROCLIENT=?" );
    System.out.println( "Executing " + sql.toString() + " with values: " + dto );
    stmt = conn.prepareStatement( sql.toString() );
    int index = 1;
    if (dto.isNumeroclientModified()) {
    stmt.setString( index++, dto.getNumeroclient() );
    }

    if (dto.isNomModified()) {
    stmt.setString( index++, dto.getNom() );
    }

    if (dto.isPrenomModified()) {
    stmt.setString( index++, dto.getPrenom() );
    }

    if (dto.isAdresseModified()) {
    stmt.setString( index++, dto.getAdresse() );
    }

    if (dto.isNationalitéModified()) {
    stmt.setString( index++, dto.getNationalité() );
    }

    if (dto.isPasseportModified()) {
    stmt.setString( index++, dto.getPasseport() );
    }

    if (dto.isPermisModified()) {
    stmt.setString( index++, dto.getPermis() );
    }

    if (dto.isTelephoneModified()) {
    stmt.setString( index++, dto.getTelephone() );
    }

    if (dto.isMailModified()) {
    stmt.setString( index++, dto.getMail() );
    }

    if (dto.isNomacModified()) {
    stmt.setString( index++, dto.getNomac() );
    }

    if (dto.isPrenomacModified()) {
    stmt.setString( index++, dto.getPrenomac() );
    }

    if (dto.isAdresseacModified()) {
    stmt.setString( index++, dto.getAdresseac() );
    }

    if (dto.isNationalitéacModified()) {
    stmt.setString( index++, dto.getNationalitéac() );
    }

    if (dto.isPasseportacModified()) {
    stmt.setString( index++, dto.getPasseportac() );
    }

    if (dto.isPermisacModified()) {
    stmt.setString( index++, dto.getPermisac() );
    }

    if (dto.isTelephoneacModified()) {
    stmt.setString( index++, dto.getTelephoneac() );
    }

    if (dto.isMailacModified()) {
    stmt.setString( index++, dto.getMailac() );
    }

    stmt.setString( index++, pk.getNumeroclient() );
    int rows = stmt.executeUpdate();
    reset(dto);
    long t2 = System.currentTimeMillis();
    System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
    }
    catch (Exception _e) {
    _e.printStackTrace();
    throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
    }
    finally {
    ResourceManager.close(stmt);
    if (!isConnSupplied) {
    ResourceManager.close(conn);
    }

    }

    }

    /**
    * Deletes a single row in the CLIENT table.
    */
    public void delete(ClientPk pk) throws ClientDaoException
    {
    long t1 = System.currentTimeMillis();
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;

    try {
    // get the user-specified connection or get a connection from the ResourceManager
    conn = isConnSupplied ? userConn : ResourceManager.getConnection();

    System.out.println( "Executing " + SQL_DELETE + " with PK: " + pk );
    stmt = conn.prepareStatement( SQL_DELETE );
    stmt.setString( 1, pk.getNumeroclient() );
    int rows = stmt.executeUpdate();
    long t2 = System.currentTimeMillis();
    System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
    }
    catch (Exception _e) {
    _e.printStackTrace();
    throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
    }
    finally {
    ResourceManager.close(stmt);
    if (!isConnSupplied) {
    ResourceManager.close(conn);
    }

    }

    }

    /**
    * Returns the rows from the CLIENT table that matches the specified primary-key value.
    */
    public Client findByPrimaryKey(ClientPk pk) throws ClientDaoException
    {
    return findByPrimaryKey( pk.getNumeroclient() );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'NUMEROCLIENT = :numeroclient'.
    */
    public Client findByPrimaryKey(String numeroclient) throws ClientDaoException
    {
    Client ret[] = findByDynamicSelect( SQL_SELECT + " WHERE NUMEROCLIENT = ?", new Object[] { numeroclient } );
    return ret.length==0 ? null : ret[0];
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria ''.
    */
    public Client[] findAll() throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " ORDER BY NUMEROCLIENT", null );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'NUMEROCLIENT = :numeroclient'.
    */
    public Client[] findWhereNumeroclientEquals(String numeroclient) throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " WHERE NUMEROCLIENT = ? ORDER BY NUMEROCLIENT", new Object[] { numeroclient } );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'NOM = :nom'.
    */
    public Client[] findWhereNomEquals(String nom) throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " WHERE NOM = ? ORDER BY NOM", new Object[] { nom } );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'NATIONALITÉ = :nationalité'.
    */
    public Client[] findWhereNationalitéEquals(String nationalité) throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " WHERE NATIONALITÉ = ? ORDER BY NATIONALITÉ", new Object[] { nationalité } );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'PASSEPORT = :passeport'.
    */
    public Client[] findWherePasseportEquals(String passeport) throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " WHERE PASSEPORT = ? ORDER BY PASSEPORT", new Object[] { passeport } );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'PERMIS = :permis'.
    */
    public Client[] findWherePermisEquals(String permis) throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " WHERE PERMIS = ? ORDER BY PERMIS", new Object[] { permis } );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'TELEPHONE = :telephone'.
    */
    public Client[] findWhereTelephoneEquals(String telephone) throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " WHERE TELEPHONE = ? ORDER BY TELEPHONE", new Object[] { telephone } );
    }

    /**
    * Returns all rows from the CLIENT table that match the criteria 'MAIL = :mail'.
    */
    public Client[] findWhereMailEquals(String mail) throws ClientDaoException
    {
    return findByDynamicSelect( SQL_SELECT + " WHERE MAIL = ? ORDER BY MAIL", new Object[] { mail } );
    }

    /**
    * Method 'ClientDaoImpl'
    *
    */
    public ClientDaoImpl()
    {
    }

    /**
    * Method 'ClientDaoImpl'
    *
    * @param userConn
    */
    public ClientDaoImpl(final java.sql.Connection userConn)
    {
    this.userConn = userConn;
    }

    /**
    * Sets the value of maxRows
    */
    public void setMaxRows(int maxRows)
    {
    this.maxRows = maxRows;
    }

    /**
    * Gets the value of maxRows
    */
    public int getMaxRows()
    {
    return maxRows;
    }

    /**
    * Method 'getTableName'
    *
    * @return String
    */
    public String getTableName()
    {
    return "CLIENT";
    }

    /**
    * Fetches a single row from the result set
    */
    protected Client fetchSingleResult(ResultSet rs) throws SQLException
    {
    if (rs.next()) {
    Client dto = new Client();
    populateDto( dto, rs);
    return dto;
    } else {
    return null;
    }

    }

    /**
    * Fetches multiple rows from the result set
    */
    @SuppressWarnings("unchecked")
    protected Client[] fetchMultiResults(ResultSet rs) throws SQLException
    {
    Collection resultList = new ArrayList();
    while (rs.next()) {
    Client dto = new Client();
    populateDto( dto, rs);
    resultList.add( dto );
    }

    Client ret[] = new Client[ resultList.size() ];
    resultList.toArray( ret );
    return ret;
    }

    /**
    * Populates a DTO with data from a ResultSet
    */
    protected void populateDto(Client dto, ResultSet rs) throws SQLException
    {
    dto.setNumeroclient( rs.getString( COLUMN_NUMEROCLIENT ) );
    dto.setNom( rs.getString( COLUMN_NOM ) );
    dto.setPrenom( rs.getString( COLUMN_PRENOM ) );
    dto.setAdresse( rs.getString( COLUMN_ADRESSE ) );
    dto.setNationalité( rs.getString( COLUMN_NATIONALITÉ ) );
    dto.setPasseport( rs.getString( COLUMN_PASSEPORT ) );
    dto.setPermis( rs.getString( COLUMN_PERMIS ) );
    dto.setTelephone( rs.getString( COLUMN_TELEPHONE ) );
    dto.setMail( rs.getString( COLUMN_MAIL ) );
    dto.setNomac( rs.getString( COLUMN_NOMAC ) );
    dto.setPrenomac( rs.getString( COLUMN_PRENOMAC ) );
    dto.setAdresseac( rs.getString( COLUMN_ADRESSEAC ) );
    dto.setNationalitéac( rs.getString( COLUMN_NATIONALITÉAC ) );
    dto.setPasseportac( rs.getString( COLUMN_PASSEPORTAC ) );
    dto.setPermisac( rs.getString( COLUMN_PERMISAC ) );
    dto.setTelephoneac( rs.getString( COLUMN_TELEPHONEAC ) );
    dto.setMailac( rs.getString( COLUMN_MAILAC ) );
    reset(dto);
    }

    /**
    * Resets the modified attributes in the DTO
    */
    protected void reset(Client dto)
    {
    dto.setNumeroclientModified( false );
    dto.setNomModified( false );
    dto.setPrenomModified( false );
    dto.setAdresseModified( false );
    dto.setNationalitéModified( false );
    dto.setPasseportModified( false );
    dto.setPermisModified( false );
    dto.setTelephoneModified( false );
    dto.setMailModified( false );
    dto.setNomacModified( false );
    dto.setPrenomacModified( false );
    dto.setAdresseacModified( false );
    dto.setNationalitéacModified( false );
    dto.setPasseportacModified( false );
    dto.setPermisacModified( false );
    dto.setTelephoneacModified( false );
    dto.setMailacModified( false );
    }

    /**
    * Returns all rows from the CLIENT table that match the specified arbitrary SQL statement
    */
    public Client[] findByDynamicSelect(String sql, Object[] sqlParams) throws ClientDaoException
    {
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
    // get the user-specified connection or get a connection from the ResourceManager
    conn = isConnSupplied ? userConn : ResourceManager.getConnection();

    // construct the SQL statement
    final String SQL = sql;


    System.out.println( "Executing " + SQL );
    // prepare statement
    stmt = conn.prepareStatement( SQL );
    stmt.setMaxRows( maxRows );

    // bind parameters
    for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
    stmt.setObject( i+1, sqlParams[i] );
    }


    rs = stmt.executeQuery();

    // fetch the results
    return fetchMultiResults(rs);
    }
    catch (Exception _e) {
    _e.printStackTrace();
    throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
    }
    finally {
    ResourceManager.close(rs);
    ResourceManager.close(stmt);
    if (!isConnSupplied) {
    ResourceManager.close(conn);
    }

    }

    }

    /**
    * Returns all rows from the CLIENT table that match the specified arbitrary SQL statement
    */
    public Client[] findByDynamicWhere(String sql, Object[] sqlParams) throws ClientDaoException
    {
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
    // get the user-specified connection or get a connection from the ResourceManager
    conn = isConnSupplied ? userConn : ResourceManager.getConnection();

    // construct the SQL statement
    final String SQL = SQL_SELECT + " WHERE " + sql;


    System.out.println( "Executing " + SQL );
    // prepare statement
    stmt = conn.prepareStatement( SQL );
    stmt.setMaxRows( maxRows );

    // bind parameters
    for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
    stmt.setObject( i+1, sqlParams[i] );
    }


    rs = stmt.executeQuery();

    // fetch the results
    return fetchMultiResults(rs);
    }
    catch (Exception _e) {
    _e.printStackTrace();
    throw new ClientDaoException( "Exception: " + _e.getMessage(), _e );
    }
    finally {
    ResourceManager.close(rs);
    ResourceManager.close(stmt);
    if (!isConnSupplied) {
    ResourceManager.close(conn);
    }

    }

    }

    @Override
    public void insert(ClientPk pk, Client dto) throws ClientDaoException {
    // TODO Auto-generated method stub

    }


    }
    code JSP insertion
    <form method="POST" >
    <input type="submit" value="Enregistrer" onclick="window.open('Rechercher.jsp','Rechercher','height=400, width=700, top=100, left=300, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=no, status=no'); return false;">
    </form>
    </tr>
    Merci de m'informer sur ce que je dois faire
    CDT

  2. #2
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    Bonjour

    c'est un peu vague ta question
    qu'est ce qui ne marche pas exactement ?
    et essaies de procéder par étape
    pour le select c'est ok
    pour l'insertion qu'est ce qui ne fonctionne pas ? Tu envoies quelles données dans ton formulaire ?.
    Quelle est l'erreur que tu obtiens ?

    Autre point puisque tu es dans les design pattern et que tu à l'air de faire tes appels en JDBC tu peux aussi utiliser le template method

Discussions similaires

  1. Insertion des fichiers pdf dans une base oracle
    Par arezki76 dans le forum SQL
    Réponses: 2
    Dernier message: 20/07/2007, 16h39
  2. importer des données XML dans une base Oracle 9
    Par lanfeustdetroll dans le forum JDBC
    Réponses: 3
    Dernier message: 19/07/2007, 00h09
  3. Réponses: 2
    Dernier message: 29/05/2007, 08h31
  4. Réponses: 1
    Dernier message: 27/09/2006, 08h50
  5. changer le type d'un attribut dans une base oracle 8i
    Par vrossi59 dans le forum Oracle
    Réponses: 3
    Dernier message: 24/02/2006, 15h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo