Solved

JDBC with SQL Server 7 and Tomcat

Posted on 2002-07-30
4
653 Views
Last Modified: 2008-03-10
I am having problems connecting JSPs to a MS SQL Server 7 database while developing an application on Tomcat (currently in standalone).

Using a Type 1 (JDBC:ODBC bridge) connection is straight forward and works in the NetBeans IDE once the ODBC is set up.  When running outside the IDE on Tomcat, the driver class file ("sun.jdbc.odbc.JdbcOdbcDriver") loads OK from the JSP, but I get an error "Data source name not found and no default driver specified".

There would appear to be 2 solutions to this:

1.  Get the type 1 connection working correctly.  No idea how to set up both the ODBC connection and the data source to be recognised by Tomcat.
2. Go for a type 3 or 4 connection.  However, MS only have a jdbc driver for SQL Server 2000 and there is no statement saying that it will work with SQL Server 7.  I assume the driver .class or .jar file has to be put in the application WEB-INF folder.  Again how do I refer to the datasource from Tomcat?

Looking forward to help on this (been stuck for a couple of days now), which I hope is a relatively straightforward problem.

Rob
0
Comment
Question by:robertcarr
  • 3
4 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 100 total points
Comment Utility
Do you create the System DSN in your System? Try something like this:

if (request.getMethod().equals("POST")) {
         if (request.getParameter("username") !=null && request.getParameter("password") !=null) {
              Driver Driverrs1 = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
              Connection Connrs1 = DriverManager.getConnection("jdbc:odbc:test","","");
              PreparedStatement Statementrs1 = Connrs1.prepareStatement("SELECT User_id, Salesrepid FROM LoginUser Where Username ='"+request.getParameter("username")+"' and Password='"+request.getParameter("password")+"'");
              ResultSet rs1 = Statementrs1.executeQuery();
              if (rs1.next()) {
                   isvalid = true;
                   session.setAttribute("username",request.getParameter("username"));
                   session.setAttribute("userid",rs1.getObject(1).toString());
                   salesrepid = rs1.getObject(2).toString();
              }
         }
    }
   
0
 

Author Comment

by:robertcarr
Comment Utility
Thanks ryancys for the above problem.  However, was setting up connection already as you stated.  Discovered the problem:  for some reason my machine had Tomcat running on W2K as a Service.  Stopping Tomcat via Control Panel, then restarting with the bat file.  For some reason my Type 1 ODBC bridge worked.

No idea why, but I'm a happy man after all this time.
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
> Discovered the problem:  for some reason my machine had Tomcat running on W2K as a Service.  Stopping Tomcat via Control Panel, then restarting with the bat file.  For some reason my Type 1 ODBC bridge worked.

> No idea why, but I'm a happy man after all this time.

Good! So do you need any futher help or you can PAQ this question by accepting my comment and the answer.

regards,
ryancys
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Just in case you still have problem in Tomcat Configuration, try look at this previous PAQ question:
Tomcat and JDK Setup:
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_20284642.html
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now