Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets and SQL Express 2005

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NEW to servlets and database. I made a database "my-users", in sql express 2005. It has a table "user-info", with columns : user and password. I want my servlet to access that table and print all the user names and passwords. I am trying to deploy this servlet in apache tomcat 5.5 on windows 7 64-bit os.

I can make it work in sql2000, but not in express 2005. Here is my code, how do i make it work ?

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exception?


// where is the dsn ?

You are using a type 4 driver, you don't need a DNS.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:What is the exception?


// where is the dsn ?

You are using a type 4 driver, you don't need a DNS.


I got this driver from the net. How does one choose a driver ? Is there a type 1 driver for this ? The servlet was compiled successfully. Here is the exception in tomcat 5.5 :



How do i find the stack trace inside the logs folder as mentioned above "note The full stack trace of the root cause is available in the Apache Tomcat/5.5.31 logs. "?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I got this driver from the net. How does one choose a driver ? Is there a type 1 driver for this ?

Why do you want to use a type 1 driver?


javax.servlet.ServletException: Class Connect is not a Servlet

The error message says it all really. Your are trying to service an HTTP request with a class that is not a Servlet.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:
javax.servlet.ServletException: Class Connect is not a Servlet
The error message says it all really. Your are trying to service an HTTP request with a class that is not a Servlet.


Sorry, it should have struck me in the 1st line of code itself. This servlet was supposed to be "called" by another. I revised the code as follows and got an error in tomcat when i try to run it by manually entering this in the browser : "http://localhost:8080/quiz/sql2005" where sql2005 is the url-pattern.

Here is the revised code :


here is the error in tomcat :
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Servlet is written to support POST requests only. If the request is a GET, you will need to implement doGet too.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:
I got this driver from the net. How does one choose a driver ? Is there a type 1 driver for this ?
Why do you want to use a type 1 driver?


A person i had asked for help told me that generally type 1 drivers are used. 2,3,4 are rarely used. Is this correct ? I am a beginner in servlets so i am not very confident now, so can you recommend any book,website etc which will be helpful. I already have kathy sierra's book which i am hardly using. most of my servlet knowledge is from the internet.

regards.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Your Servlet is written to support POST requests only. If the request is a GET, you will need to implement doGet too.


how do i do that ? I want to make my servlet access the table in database and print all the user names and passwords on the screen.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, very wrong. A type 1 driver is the JDBC-ODBC bridge which is not for production software (as Oracle state). Type 4 is (in my experience) by far the most widely used, probably because it is the only one that can run without any specific changes or configuration made to the environment it is run in.

I can't recommend a book - it is years since I read a Servlet book. The Servlet specification is a good thing to read (essential, if you are going to be using Servlets long term). A simpler entry point is the JEE tutorial.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:No, very wrong. A type 1 driver is the JDBC-ODBC bridge which is not for production software (as Oracle state). Type 4 is (in my experience) by far the most widely used, probably because it is the only one that can run without any specific changes or configuration made to the environment it is run in.

I can't recommend a book - it is years since I read a Servlet book. The Servlet specification is a good thing to read (essential, if you are going to be using Servlets long term). A simpler entry point is the JEE tutorial.


can you suggest corrections to my program so that it works properly ?

thanks for hearing patiently.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Servlets you need to implement a method for each HTTP method you intended to support. If you are not sure what an HTTP method is I'd stop trying to write code for an few moments and go read up on them. (see the link I supplied). Your Servlet (as written) supports POST, but you are using GET. Have a read of the JavaDocs for the class HttpServlet your Servlet is extending.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic