I've been trying to obtain the Driver class for JDBC connection to MySQL.
The workstation is running on Linux, Fedora 10.
I have manually set up the classpath variable for Java by CLI like this:
bash-3.2$ echo $CLASSPATH
/home/cmao/public_html/jsp/mysql-connector-java-5.1.12-bin.jar
This shows that I've added the lastest mysql connection jar archive to my CLASSPATH variable.
I've created a test JSP page which can be found here
And source code for this page is:
<%@page language="java"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<html>
<head>
<title>UTS JDBC MySQL connection test page</title>
</head>
<body>
<%
Connection con = null;
out.print("Java version is : " + System.getProperty("java.version") + "<br />");
out.print("Tomcat version is : " + application.getServerInfo() + "<br />");
out.print("Servlet version is: " + application.getMajorVersion() + "<br />");
out.print("JSP version is : " + JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() +"<br />");
//out.print("Java classpath is : " + System.getProperty("java.class.path")+ "<br />");
//out.print("JSP classpath is : " + appliaction.getAttribute("org.apache.catalina.jsp_classpath") + "<br />");
//out.print("Tomcat classpath is : " + System.getProperty("org.apache.tomcat.common.classpath") + "<br />");
try
{
Class c = Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e)
{
out.println("Error! Failed to obtain JDBC driver for MySQL... Missing class "com.mysql.jdbc.Driver"<br />");
}
%>
</body>
</html>
None of those commented out line would work, various Jsper Expetions would be thrown.
You can check those Error pages from the following links:
classpath Error page
catalina Error page
tomcat Error page
It seems, from my limited knowledge of JSP and Servlet, the Tomcat environment "ignores" my Java CLASSPATH? In which case I cannot configure the MySQL JDBC package to let my Servlets(a JSP is but a Servlet anyway) work.
I am not sure how to fix this issue. would it be better if I use an IDE like Eclipse or NetBeans and create a real Java "web app" so that everything can be "self-configured" by the usage of a web.config XML configuration file? So that I can certainly bypass this Tomcat environment restriction?
Many thanks for the suggestions in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…