0

Hi everyone,

I searched a while on the internet how to work with mvc for a school project.
I found a really great tutorial on this site. (http://www.daniweb.com/forums/thread141776.html)
This tutorial has everything that i needed.

In this tutorial the connection of the database is made by setting paramaters in de xml:

<servlet>
        <servlet-name>loginServlet</servlet-name>
        <servlet-class>servlet.loginServlet</servlet-class>
        <init-param>
            <param-name>jdbcDriver</param-name>
            <param-value>com.mysql.jdbc.Driver</param-value>
        </init-param>
        <init-param>
            <param-name>dbURL</param-name>
            <param-value>jdbc:mysql://127.0.0.1:3306/cijfersysteem</param-value>
        </init-param>
        <init-param>
            <param-name>dbUserName</param-name>
            <param-value>vishant</param-value>
        </init-param>
        <init-param>
            <param-name>dbPassword</param-name>
            <param-value>vishant</param-value>
        </init-param>
    </servlet>

My login is working great, just like the tutorial explained.

But now i'm making another page ProfileServlet.java and i want to get info from the database and i get the following error:

SEVERE: java.sql.SQLException: No suitable driver found for 
        at java.sql.DriverManager.getConnection(DriverManager.java:602)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at model.DataManager.getConnection(DataManager.java:77)
        at model.DataManager.getRichtingen(DataManager.java:262)
        at servlet.ProfileServlet.processRequest(ProfileServlet.java:36)
        at servlet.ProfileServlet.doGet(ProfileServlet.java:63)

Do i need to go in the web.xml and set the parameters for the ProfileServlet to?
For example:

<servlet>
        <servlet-name>ProfileServlet</servlet-name>
        <servlet-class>servlet.ProfileServlet</servlet-class>
        <init-param>
            <param-name>jdbcDriver</param-name>
            <param-value>com.mysql.jdbc.Driver</param-value>
        </init-param>
        <init-param>
            <param-name>dbURL</param-name>
            <param-value>jdbc:mysql://127.0.0.1:3306/cijfersysteem</param-value>
        </init-param>
        <init-param>
            <param-name>dbUserName</param-name>
            <param-value>vishant</param-value>
        </init-param>
        <init-param>
            <param-name>dbPassword</param-name>
            <param-value>vishant</param-value>
        </init-param>
    </servlet>

Does this mean that i need to do this for every servlet? Which is not efficient.

Help needed for this please.

Thnx in advance.

Edited by vishantpoeran: n/a

2
Contributors
1
Reply
6
Views
7 Years
Discussion Span
Last Post by ~s.o.s~
0

> Does this mean that i need to do this for every servlet? Which is not efficient.

Yes, it's not efficient. The best approach when dealing with database resources would be using the connection pooling capabilities offered by your container. In case of application servers like Glassfish, Jboss etc. look into the application server documentation for creating a connection pool and exposing it over JNDI using the admin console of that app server.

In case you are using a simple container like Tomcat, Jetty etc. look into the documentation provided to get a list of configuration files which need to be changed/created to expose a connection pool over JNDI.

In case you are required to programatically manage your connection pools, look into the discussion present in this thread and post if you still have issues.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.