Took
six seven months but I finally figured out a solution. Here is my environment:
Desktop: Virtual Windows XP 32 bit
Tomcat7 on Ubuntu Server 10.4
Java7
database: Microsoft SQL server 2000 , no longer supported by MS
database server: Windows 2000, no longer supported by MS
JDBC: jtds-1.3.0.jar
additional jars: jstl.jar, standard.jar
The problem was I had an older servlet application generously posted on the web by Marty Hall and Larry Brown with source code at
coreservlets.com . They had built a Northwind servelt that accessed the Northwind database that comes with Microsoft Access and queried the database. The same Northwind database comes on all installations of Microsoft SQLserver. By putting my sqlserver's url into this old servlet and by adding jtds-1.2.5.jar to the project I was able to query my tables.
Then I wanted to modernize, take the scriplets out of the
JSP, hide the user login that in the old code was part of the html form submitting the query and could be seen by the user if they looked at the pagesource. And I could never get the connection to the sqlserver to work. The new jtds compiled fine and it is a jdbc4 driver but it never worked.
Another contributing factor was the
IDE's. I started in Netbeans because I was using a textbook with source code and that is what all the projects were built in. Then I moved to Eclipse because there were IDE issues in Netbeans that Eclipse seemed to work with. Eventually I moved the project into a Tomcat source code layout ( thank-you
Bear! ) and learned
Ant. With some help from the ANT forums and some experience from the
Cattle Drive servlet projects I was able to find the problems more quickly.
The .dbo issue I mentioned in the original post was probably a red herring and the real issue all along was not being able to make the connections.
Much of the code below is adapted from projects in the
Murachs Servlets and JSP book 2nd edition. I recommend it and appreciate that the code for full projects is part of the book. Any errors or bad practices are mine.
Here is what I found. Even though this is a jdbc 4 driver and the Class.forName(driver) doesn't have to be used according to all the examples of servlets with this generation of driver that I have found, I have to use it to connect to my sqlserver. Doesn't matter what generation of driver, it has to be used. Maybe because the sqlserver is so old? I don't know. Because I have to use the Class.forName(driver) I have to have extra catch statements to handle it . Once these issues were resolved I was able to make a very simple search program that runs. The code for my servlet and JSP is below. I hope this helps anyone else out there that has dealt with these issues.
Below is the servlet. It is not the code for Northwind but for a similar customer table.