• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with connected to database

 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project that uses servlets and jsps that displays houses from a database like a property website.
I am trying to create a log in servlet but I am getting an error.
the problem is with the line connection = PropertyDB.doConnection(); in the login servlet
it won't allow me to put connection is equal to the function.

here is the login servlet class:


and here is the class that contains the connection code for the database:

 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the doConnection() method "void" when the servlet expects a Connection?

Another problem is you are using JbdcRowSetImpl which is not a java.sql.Connection type but a JdbcRowSet (an interface).

The JdbcRowSet is a thin wrapper for ResultSet which means the lines:


can become


 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
removing void from doConnection just causes more errors
 
Joe Areeda
Ranch Hand
Posts: 332
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karen Wilson wrote:removing void from doConnection just causes more errors

Hi Karen,

I think agree with K. Tsang that doConnection should return a Connection object reference, but I also don't see how a connection get created.

If we look at your statement:


The thing that stands out is PropertyDB.doConnection() being type void can't set the variable connection. Doesn't that produce a compiler error?

So the mod to your code might look something like:



Joe
 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the code but I get an error with the line return conn - "cannot return a value from method whose return type is void"

also when I try call conn = PropertyDB.doConnection(); in the servlet class I get the error saying it can't find conn
but I added the import for the PropertyDB page
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return type of the method can't be void as you are returning something from there. So it should look like

 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but what about the problem with conn = PropertyDB.doConnection(); in the servlet file?
I still get the error saying it can't find conn
 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i solved it. I had to put Connection conn = PropertyDB.doConnection();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic