SWB-Consulting
asked on
MS SQL Database Connection Using JSP (with JTDS)
Hi,
I'm testing a JSP page that is used for connecting to MSSQL database. It uses JTDS driver. Below are the file sructures:
1. C:\apache-tomcat\webapps\M yPage\test Sql.jsp
2. C:\apache-tomcat\common\li b\jtds-1.2 .jar <---- the JTDS jar file
3. C:\apache-tomcat\webapps\M yPage\WebR oot\WEB-IN F\web.xml
1. web.xml:
*********
<?xml version="1.0" encoding="UTF-8" ?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" />
2. testSql.jsp:
**********
<%@ page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"% >
<html>
<body>
<%
Connection conn;
try {
Class.forName(net.sourcefo rge.jtds.j dbc.Driver );
} catch (ClassNotFoundException ex) {
}
try {
conn = DriverManager.getConnectio n("jdbc:jt ds:sqlserv er://xx.xx .xx.xx:143 3/Database Name", "UserName", "Password");
} catch (Exception e) {
throw e;
}
%>
</body>
</html>
When I run the testSql.jsp, it produces the following error:
An error occurred at line: 11 in the jsp file: /testSql.jsp
Generated servlet error:
net.sourceforge.jtds.jdbc. Driver cannot be resolved
org.apache.jasper.compiler .DefaultEr rorHandler .javacErro r(DefaultE rrorHandle r.java:84)
org.apache.jasper.compiler .ErrorDisp atcher.jav acError(Er rorDispatc her.java:3 28)
org.apache.jasper.compiler .JDTCompil er.generat eClass(JDT Compiler.j ava:414)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:297)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:276)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:264)
org.apache.jasper.JspCompi lationCont ext.compil e(JspCompi lationCont ext.java:5 63)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 05)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:314)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:264)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
Does anyone know what is the problem?
Thanks
I'm testing a JSP page that is used for connecting to MSSQL database. It uses JTDS driver. Below are the file sructures:
1. C:\apache-tomcat\webapps\M
2. C:\apache-tomcat\common\li
3. C:\apache-tomcat\webapps\M
1. web.xml:
*********
<?xml version="1.0" encoding="UTF-8" ?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" />
2. testSql.jsp:
**********
<%@ page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%
<html>
<body>
<%
Connection conn;
try {
Class.forName(net.sourcefo
} catch (ClassNotFoundException ex) {
}
try {
conn = DriverManager.getConnectio
} catch (Exception e) {
throw e;
}
%>
</body>
</html>
When I run the testSql.jsp, it produces the following error:
An error occurred at line: 11 in the jsp file: /testSql.jsp
Generated servlet error:
net.sourceforge.jtds.jdbc.
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.JspCompi
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
Does anyone know what is the problem?
Thanks
ASKER
Still the same error message. I tried to move the jtds-1.2.jar to the following folder:
- First to C:\apache-tomcat\webapps\M yPage\WebR oot\WEB-IN F\lib (doesn't work)
- Then I moved it to C:\apache-tomcat\webapps\M yPage\WEB- INF\lib (still doesn't work)
Do I need to edit the web.xml or am I missing a file or something?
- First to C:\apache-tomcat\webapps\M
- Then I moved it to C:\apache-tomcat\webapps\M
Do I need to edit the web.xml or am I missing a file or something?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes i think suprato45 answer must do the trick yet if u get the same error again just put that "jtds-1.2.jar" in to ur WEB-INF/lib folder and try again it must work.
ASKER
Indeed it works. I should be more careful next time. Thanks suprato45!
Move the jtds-1.2.jar to your C:\apache-tomcat\webapps\M