Solved

MS SQL Database Connection Using JSP (with JTDS)

Posted on 2006-11-21
5
814 Views
Last Modified: 2012-05-05
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\MyPage\testSql.jsp
2. C:\apache-tomcat\common\lib\jtds-1.2.jar  <---- the JTDS jar file
3. C:\apache-tomcat\webapps\MyPage\WebRoot\WEB-INF\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.sourceforge.jtds.jdbc.Driver);
       } catch (ClassNotFoundException ex) {
       }
 
 try {
           conn = DriverManager.getConnection("jdbc:jtds:sqlserver://xx.xx.xx.xx:1433/DatabaseName", "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.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Does anyone know what is the problem?

Thanks
0
Comment
Question by:SWB-Consulting
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17993552
>>"2. C:\apache-tomcat\common\lib\jtds-1.2.jar  <---- the JTDS jar file"

Move the jtds-1.2.jar to your C:\apache-tomcat\webapps\MyPage\WEB-INF\lib.
0
 

Author Comment

by:SWB-Consulting
ID: 17997813
Still the same error message.  I tried to move the jtds-1.2.jar to the following folder:
- First to C:\apache-tomcat\webapps\MyPage\WebRoot\WEB-INF\lib (doesn't work)
- Then I moved it to C:\apache-tomcat\webapps\MyPage\WEB-INF\lib (still doesn't work)

Do I need to edit the web.xml or am I missing a file or something?
0
 
LVL 16

Accepted Solution

by:
suprapto45 earned 500 total points
ID: 18000319
I thought that it shoould be

Class.forName("net.sourceforge.jtds.jdbc.Driver");
instead of
Class.forName(net.sourceforge.jtds.jdbc.Driver);
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 18016593
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.

0
 

Author Comment

by:SWB-Consulting
ID: 18133283
Indeed it works. I should be more careful next time. Thanks suprato45!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question