Solved

JDBC with SQL Server 7 and Tomcat

Posted on 2002-07-30
4
666 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 52

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 52

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 52

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

Independent Software Vendors: 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

Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

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