Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JDBC with SQL Server 7 and Tomcat

Posted on 2002-07-30
4
Medium Priority
?
674 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 53

Accepted Solution

by:
Ryan Chong earned 400 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 53

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 53

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

WooCommerce is becoming the most powerful e-commerce plugin for Wordpress. And why not. The platform comprises of numerous core plugins that may come in handy, powerful options to make your website development task much easier.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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