views:

26

answers:

2

I am designing a small web application for learning purpose using Apache Tomcat, Eclipse, Java EE (Servlet, JSP, Bean), MySql Database as backend. I have configured Eclipse to include Tomcat, MySql connector.

The Project:

  1. A HTML form for entering UserName, Email, and Password.
  2. Servlet for passing parameter to Java Bean.
  3. Java Bean to passing parameter to MySql database.

What's Working: The application runs when the Java Bean has no connectivity to database using (return statement).

What's not working: The application does not work when I use database connectivity in Java Bean. And the MySql database is not updated with parameters.

What I did: I checked with database connectivity it's working fine with individual Java Class files and it can pass parameters to MySql database.

I think there is some problem in my Web Application and not connectivity with database. So can anyone suggest what i should do?

A: 

The Stacktrace would help. ClassNotFoundException ?

Is the JDBC-Driver included to the web-Archive?

Have you tried to put the driver into the server/lib Directory ?

ckuetbach
A: 

I am getting this Exception while running the web application on server: Got an exception! com.mysql.jdbc.Driver

Although the exception handling is poor (exception type is completely missing), the exception message com.mysql.jdbc.Driver is typical for a ClassNotFoundException. This is pretty self-explaining: the class or at least the JAR file containing the class is missing in the runtime classpath.

To fix this, all you need to do is to put the MySQL JDBC driver JAR file in the classpath. If you aren't faciliting the container managed JNDI datasource, just dropping the JAR file in webapp's /WEB-INF/lib folder is sufficient. But if you're utilizing a JNDI datasource (strongly recomment, offers connection pooling, better performance), then you need to drop the JAR file in servletcontainer's classpath. In Tomcat, that would be its /lib folder.

That said, please improve your exception handling. Don't do a nothing-saying

} catch (Exception e) {
    System.out.println("Got an exception! " + e.getMessage());
}

but rather throw it through or do at least e.printStackTrace().

BalusC