?
Solved

JDBC with SQL Server 7 and Tomcat

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

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 54

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 54

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 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