January 14th, 2006, 10:16 PM
Connect using JSP to mysql database.
I am slowly trying to get away from ASP and try using JSP. Although right now I feel like a novice swimmer who just realized he can't touch the bottom of the pool and doesn't yet know how to swim...
Anyway, my problem is this...
is resulting in the following error..
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/DBNAME","USER_NAME","PASSWORD");
So I assume the problem is this: java.lang.NoClassDefFoundError: org/apache/jasper/runtime/JspException, but I am not sure how to correct it.
Pls help me touch bottom again!
January 15th, 2006, 02:05 AM
You need to find out what line in the JSP page threw the exception. JSP pages are translated by Tomcat into Java source files, which are stored in the server's /work directory. The path will be something like /work/localhost/.../testdb$jsp.java (starting at the Tomcat home directory). That code gets compiled into a Java class when you open your JSP page in the browser for the first time. So, you need to find out what happens at line 88 in that Java source file and what line it corresponds to in your actual page (testdb.jsp).
I am guessing the error is caused by the JVM's not being able to load the MySQL JDBC driver, hence the ClassNotFoundException. If that is the case, you need to put the jar file containing the driver into the appropriate Tomcat directory. Either into /WEB-INF/lib for your application only or into one of the top-level directories (I think it's /common) if you want other web apps in the server to use it.
Second, you should not really be putting this kind of code into JSP pages. Database operations should happen in the objects that are working behind the scene, not the JSP page. The JSP page should mostly be used for presentation logic. It's really a huge topic, but if you want to get some idea, read up on the MVC design pattern for web programming or on the various Java web frameworks like Struts, Spring, etc.
Hope this helps.
Comments on this post