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 :

2 sessions non hermétiques


Sujet :

Servlets/JSP Java

  1. #21
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    Tout simplement l'erreur 10061 :

    [mysql][odbc 3.51 driver] Can't connect to MySQL server on 'srv' (10061)

  2. #22
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    J'ai changé le driver. J'ai ajouté le connector.jar au projet et changé l'url.
    Malheureusement, j'ai toujours le soucis de connexion à la base de données.

  3. #23
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    on peux avoir la stacktrace complete de tes erreurs?

  4. #24
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    Voici un exemple

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    java.sql.SQLException: [MySQL][ODBC 5.1 Driver]Can't connect to MySQL server on 'srv' (10048)
            at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
            at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
            at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
            at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
            at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
            at java.sql.DriverManager.getConnection(DriverManager.java:582)
            at java.sql.DriverManager.getConnection(DriverManager.java:185)
            at engine.DataBase.connection(DataBase.java:40)
            at engine.DataBase.getResult(DataBase.java:55)
            at DAO.FamillyDAO.getContainId(FamillyDAO.java:182)
            at engine.EngineMethods.viewableBoxesCollectionMaker(EngineMethods.java:111)
            at servlets.SearchEngine.processRequest(SearchEngine.java:56)
            at servlets.SearchEngine.doGet(SearchEngine.java:426)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
            at java.lang.Thread.run(Thread.java:619)
    java.lang.NullPointerException
            at DAO.FamillyDAO.getContainId(FamillyDAO.java:183)
            at engine.EngineMethods.viewableBoxesCollectionMaker(EngineMethods.java:111)
            at servlets.SearchEngine.processRequest(SearchEngine.java:56)
            at servlets.SearchEngine.doGet(SearchEngine.java:426)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
            at java.lang.Thread.run(Thread.java:619)
    Voici les instructions de la méthode :
    La ligne 40 est en gras

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    public Connection connection () throws SQLException {
            Connection con;
            try {Class.forName("com.mysql.jdbc.Driver");}
            catch (ClassNotFoundException e) {System.out.println("ClassNotFoundException");}
            con = DriverManager.getConnection(url, userName, password);
            st = con.createStatement();
            return con;
        }
    l'url : this.url = "jdbc:odbc:Javarch";//database adress

  5. #25
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    essaie de virer ce pont odbc et utiliser directement le driver mysql, avec une url de la form

    jdbc:mysql://server/myDb?user=monty&password=greatsqldb

  6. #26
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    C'est fait je vais voir ce que ça donne !

    Merci beaucoup en tout cas !!

  7. #27
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    Je crois que je n'ai pas précisé une chose parce que la connexion ne se connecte toujours sur un même port. Je ne comprends pas à vrai dire


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.
     
    This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. 
     
    For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.
     
    For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
            at sun.reflect.GeneratedConstructorAccessor12.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
            at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
            at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
            at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308)
            at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
            at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
            at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
            at sun.reflect.GeneratedConstructorAccessor9.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
            at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
            at java.sql.DriverManager.getConnection(DriverManager.java:582)
            at java.sql.DriverManager.getConnection(DriverManager.java:185)
            at engine.DataBase.connection(DataBase.java:40)
            at engine.DataBase.getResult(DataBase.java:55)
            at DAO.BoxDAO.isExists(BoxDAO.java:150)
            at DAO.BoxDAO.getBox(BoxDAO.java:121)
            at org.apache.jsp.order_jsp._jspService(order_jsp.java:229)
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
            at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
            at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
            at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
            at servlets.AddToBasket.processRequest(AddToBasket.java:79)
            at servlets.AddToBasket.doPost(AddToBasket.java:113)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
            at java.lang.Thread.run(Thread.java:619)
    Caused by: java.net.BindException: Address already in use: connect
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
            at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
            at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
            at java.net.Socket.connect(Socket.java:518)
            at java.net.Socket.connect(Socket.java:468)
            at java.net.Socket.<init>(Socket.java:365)
            at java.net.Socket.<init>(Socket.java:208)
            at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
            at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
            ... 51 more

  8. #28
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    avez vous essayé ce qui est indiqué dans le message d'erreur?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. 
     
    For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.
     
    For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).

  9. #29
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    J'ai tappé Microsoft Knowledge Base Article 196271 sur google pour savoir de quoi ça parle et comment ça se configure. Mais je ne trouve toujours rien qui peut m'aider

  10. #30
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    la question de base, c'est qu'est-ce que tu fait avec tes ports pour en utiliser plus de 3000 ?

    Sinon, dans la kb
    http://support.microsoft.com/kb/196271

    il est indiqué comment augmenter le nombre de ports éphèmères.

  11. #31
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    3000 ???? Il y a un truc qui ne va pas !!

    Dans toutes mes Servlet, j'ai des DAO qui sont singletons et ont un attribut Object[][] qui contient le résultat de la requete. Je travaille uniquement sur ce tableau.

    Ce tableau est fait dans la classe DataBase :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    public class DataBase{
        private String url, userName, password;
        private Statement st;
     
        /**
         * @author Brice
         * Constructor
         */
        private DataBase () throws SQLException {
            //attributes constructor
            this.userName = "root";//user of database
            this.password = "a";//password to connect database
            this.url = "jdbc:mysql://srv-arche/Javarch?user=root&password=a";//database adress
        }
     
        public static DataBase getIstance () {
            try {return new DataBase();}
            catch (SQLException ex) {ex.printStackTrace();return null;}
        }
        /**
         * @param void
         * @return void
         * Connect the programm to database
         */
        public Connection connection () throws SQLException {
            Connection con;
            try {Class.forName("com.mysql.jdbc.Driver");}
            catch (ClassNotFoundException e) {System.out.println("ClassNotFoundException");}
            con = DriverManager.getConnection(url, userName, password);
            st = con.createStatement();
            return con;
        }
     
        /**
         * @param String request
         * @return ResultSet
         * Execute a querry request on database and return an Object[][]
         */
        public Object[][] getResult (String request) {
            ResultSet rs = null;
            PreparedStatement pst = null;
            Connection con = null;
            try {
                con = connection();
                rs = st.executeQuery(request);
                int numberField = rs.getMetaData().getColumnCount();
                int size =0;
                ArrayList<Object> [] listArrays = new ArrayList[numberField];//arrayList collection
                //building arrayList collection
                for (int i=0; i<numberField; i++) {
                    listArrays[i] = new ArrayList <java.lang.Object>();
                }
     
                while(rs.next()) {
                  size++;//match number rows from the database result
                  for (int i=0; i<numberField; i++) {
                      listArrays[i].add(rs.getString(i+1));
                  }
                }
                Object[][] ret = new Object[size][numberField];
                for (int i=0; i<listArrays[0].size(); i++) {
                    for (int j=0; j<listArrays.length; j++) {
                        ret[i][j] = listArrays[j].get(i);
                    }
                }
                return ret;
            }
            catch (SQLException sql){sql.printStackTrace();return null;}
            finally {
                try {
                    rs.close();
                    pst.close();
                    con.close();
                }
                catch (SQLException sql){}
                catch (NullPointerException np) {}
            }
        }
    }

  12. #32
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    combien d'appel à database.getConnection() sur une tranche de 15 minutes ?

    Notez que le 3000 concerne l'ensemble des applications qui tournent sur l'OS (browser, IDE, etc) et qu'il faut un délai de 15 minute pour qu'un connection fermée soit utilisable à nouveau.

  13. #33
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    Ah oui, c'est beaucoup plus compréhensible dans ces cas là !!
    A l'affichage de la page j'affiche le contenu de ce que j'appelle une famille. J'en mets maximum 100 sur la page (en tout il peut, dans la famille, en avoir plusieurs dizaines de milliers). Du coup ma jsp appelle le get qui appelle le constructeur de la classe en lui envoyant une clé. Donc il peut y avoir 100 connexions en 1 secondes. Si plusieurs clients sont connectés en même temps, plusieurs pages sont affichés dans un court intervalle de temps, d'autant plus qu'un client peu faire apparaitre plusieurs pages en une minute.
    J'ai aussi une appli lourde qui utilise cette BDD.

    3000 en 15 minutes, est donc insuffisant.

    C'est "propre" d'augmenter le nombre de connexions comme dit dans la kb ? PAr contre ils ne parlent pas de 15 minutes.

  14. #34
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    non ce qui est propre c'est de te limiter à une seule connection DB / requete http

  15. #35
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    Ce qui veut dire que c'est la session qui a une connexion à la BDD et que je ferme uniquement mers resultsets ?

    Ma classe deviendrais alors :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    public class DataBase{
        private String url, userName, password;
        private Statement st;
        private Connection con;
     
        /**
         * @author Brice
         * Constructor
         */
        private DataBase () throws SQLException {
            //attributes constructor
            this.userName = "root";//user of database
            this.password = "a";//password to connect database
            this.url = "jdbc:mysql://srv-arche/Javarch?user=root&password=a";//database adress
        }
     
        public static DataBase getIstance () {
            try {return new DataBase();}
            catch (SQLException ex) {ex.printStackTrace();return null;}
        }
        /**
         * @param void
         * @return void
         * Connect the programm to database
         */
        public void connection () throws SQLException {
            try {Class.forName("com.mysql.jdbc.Driver");}
            catch (ClassNotFoundException e) {System.out.println("ClassNotFoundException");}
            con = DriverManager.getConnection(url, userName, password);
            st = con.createStatement();
        }
     
        /**
         * @param String request
         * @return ResultSet
         * Execute a querry request on database and return an Object[][]
         */
        public Object[][] getResult (String request) {
            ResultSet rs = null;
            PreparedStatement pst = null;
            Connection con = null;
            try {
                rs = st.executeQuery(request);
                int numberField = rs.getMetaData().getColumnCount();
                int size =0;
                ArrayList<Object> [] listArrays = new ArrayList[numberField];//arrayList collection
                //building arrayList collection
                for (int i=0; i<numberField; i++) {
                    listArrays[i] = new ArrayList <java.lang.Object>();
                }
     
                while(rs.next()) {
                  size++;//match number rows from the database result
                  for (int i=0; i<numberField; i++) {
                      listArrays[i].add(rs.getString(i+1));
                  }
                }
                Object[][] ret = new Object[size][numberField];
                for (int i=0; i<listArrays[0].size(); i++) {
                    for (int j=0; j<listArrays.length; j++) {
                        ret[i][j] = listArrays[j].get(i);
                    }
                }
                return ret;
            }
            catch (SQLException sql){sql.printStackTrace();return null;}
            finally {
                try {
                    rs.close();
                    pst.close();
                }
                catch (SQLException sql){}
                catch (NullPointerException np) {}
            }
        }
    }
    Un objet de la classe serait donc stocké dans un attribut de la session et je m'en sers pour récupérer mes données.

    Ca me semble pas mal...

  16. #36
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    non, pas la session, la requete. Elle doit etre fermée à la fin de la requete http.


    Si tu l'ouvre à chaque "get", tu va saturer le serveur sql de demande de connections
    Si tu l'ouvre une seule fois par session, tu va faire maintenir par le serveur sql des session inutile + tu aura de problèmes à gérer les requetes en parallèle.

  17. #37
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    Donc connexion au début de chaque servlet et déconnexion à la fin.Idem pour les jsp ?

  18. #38
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    En gros oui, c'est ce que j'essayais de te faire comprendre dans mon précédent post...

    Le mieux serait :

    - ouverture de la connexion au début du request
    - fermeture de la connexion à la fin de response

    Si tu utilises un framework MVC2 (comme struts ou jsf), il existe un point d'entrée systématique qui est modifiable pour y injecter une fermeture propre.
    Sinon, tu peux utiliser un filtre également.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  19. #39
    Membre Expert
    Homme Profil pro
    Dév. Java & C#
    Inscrit en
    Octobre 2002
    Messages
    1 414
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Dév. Java & C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2002
    Messages : 1 414
    Par défaut
    Citation Envoyé par oneagaindoguys Voir le message
    3000 ???? Il y a un truc qui ne va pas !!

    Dans toutes mes Servlet, j'ai des DAO qui sont singletons et ont un attribut Object[][] qui contient le résultat de la requete. Je travaille uniquement sur ce tableau.

    Ce tableau est fait dans la classe DataBase :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    public class DataBase{
        private String url, userName, password;
        private Statement st;
     
        /**
         * @author Brice
         * Constructor
         */
        private DataBase () throws SQLException {
            //attributes constructor
            this.userName = "root";//user of database
            this.password = "a";//password to connect database
            this.url = "jdbc:mysql://srv-arche/Javarch?user=root&password=a";//database adress
        }
     
        public static DataBase getIstance () {
            try {return new DataBase();}
            catch (SQLException ex) {ex.printStackTrace();return null;}
        }
        /**
         * @param void
         * @return void
         * Connect the programm to database
         */
        public Connection connection () throws SQLException {
            Connection con;
            try {Class.forName("com.mysql.jdbc.Driver");}
            catch (ClassNotFoundException e) {System.out.println("ClassNotFoundException");}
            con = DriverManager.getConnection(url, userName, password);
            st = con.createStatement();
            return con;
        }
     
        /**
         * @param String request
         * @return ResultSet
         * Execute a querry request on database and return an Object[][]
         */
        public Object[][] getResult (String request) {
            ResultSet rs = null;
            PreparedStatement pst = null;
            Connection con = null;
            try {
                con = connection();
                rs = st.executeQuery(request);
                int numberField = rs.getMetaData().getColumnCount();
                int size =0;
                ArrayList<Object> [] listArrays = new ArrayList[numberField];//arrayList collection
                //building arrayList collection
                for (int i=0; i<numberField; i++) {
                    listArrays[i] = new ArrayList <java.lang.Object>();
                }
     
                while(rs.next()) {
                  size++;//match number rows from the database result
                  for (int i=0; i<numberField; i++) {
                      listArrays[i].add(rs.getString(i+1));
                  }
                }
                Object[][] ret = new Object[size][numberField];
                for (int i=0; i<listArrays[0].size(); i++) {
                    for (int j=0; j<listArrays.length; j++) {
                        ret[i][j] = listArrays[j].get(i);
                    }
                }
                return ret;
            }
            catch (SQLException sql){sql.printStackTrace();return null;}
            finally {
                try {
                    rs.close();
                    pst.close();
                    con.close();
                }
                catch (SQLException sql){}
                catch (NullPointerException np) {}
            }
        }
    }
    La classe DataBase n'est pas un singleton vu qu'à chaque appel à la méthode statique "getIstance", une nouvelle instance de DataBase est retournée.

  20. #40
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Par défaut
    Citation Envoyé par jowo Voir le message
    La classe DataBase n'est pas un singleton vu qu'à chaque appel à la méthode statique "getIstance", une nouvelle instance de DataBase est retournée.
    Ce code n'est pas le code original.

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 3 PremièrePremière 123 DernièreDernière

Discussions similaires

  1. Variable session non retenue / problème sur Firefox
    Par hatembr dans le forum Langage
    Réponses: 10
    Dernier message: 25/04/2007, 17h22
  2. Réponses: 5
    Dernier message: 24/10/2006, 11h56
  3. session non reconnue sur autre pc
    Par Makari dans le forum Langage
    Réponses: 6
    Dernier message: 24/08/2006, 13h54
  4. Ajouter une clé pour une session non ouverte
    Par prgasp77 dans le forum Windows
    Réponses: 4
    Dernier message: 29/10/2005, 00h26
  5. [Session Context] session non transmise
    Par patricetouner dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 29/12/2004, 14h56

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