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:
- A HTML form for entering UserName, Email, and Password.
- Servlet for passing parameter to Java Bean.
- Java Bean to passing parameter to MySql databas开发者_运维知识库e.
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?
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()
.
精彩评论