Solved

JDBC with SQL Server 7 and Tomcat

Posted on 2002-07-30
4
665 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
[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
  • 3
4 Comments
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 100 total points
ID: 7189742
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
ID: 7232171
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 51

Expert Comment

by:Ryan Chong
ID: 7235289
> 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 51

Expert Comment

by:Ryan Chong
ID: 7235293
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
runtime exception and error differences 4 91
tomcat startup error 5 136
servlet example 17 59
dao vs facade design patterns 2 39
Read the original post on Monitis Blog. Believe it or not, the most important thing about the website of your business is not what’s on it but how fast it loads. Yes, that’s right!    As you can see on this infographic (an oldie but goodie!), …
This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

697 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