Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need HELP!!!  Are beans dropping my connection?

Posted on 2004-08-12
13
Medium Priority
?
291 Views
Last Modified: 2010-04-01
I am the first in our office to implement javabeans into a project.  Normally we just access the database, store in variables and pass either in hidden fields or in the URL to the next page.  Now I am having major issues and I need to know if it is the beans causing my problems.

Pages that loaded correctly are now not loading correctly.  There are too many instances to go into but the pages just don't display well.  Though some will if they are refreshed.  If there was a problem with my code would it not display at all everytime I get the page instead of clearing up when refreshed?  Or loading sometimes but not others? (and I mean with a 10 minute period).  

I was demoing the project this morning, there was nothing wrong.  It ran perfectly.  Then all of a sudden pages that were displaying properly wouldn't display anymore.  We demoed for over an hour before it crapped out.  I don't think its the code because if there was a problem with it I would have gotten these errors on my machine (we were demoing on the boss' machine in another room).  He thinks the problem is the javabeans.

Tomcat is giving me the error:
[Microsoft][SQLServer 2000 Driver for JDBC]Connection reset by peer: socket write error

I know this isn't the sql forum but what I need to know is if javabeans can give me this error?  Can they cause any errors that I might not be familiar with?  Should I switch back to using request.getParameter to pass all data?  I need to have a finished demo on Tuesday so I need to know fast if I need to convert all the beans over to the old request.getParameter style?
0
Comment
Question by:SweetChastity
[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
  • 8
  • 2
  • 2
  • +1
13 Comments
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 450 total points
ID: 11785824
SOunds like SQLServer is dropping connections...  

How many do you have acticve at once?  
Do you use a connection pool?
Are you sure you close your connections and statements after each db call?  (try...catch...finally block)?
0
 
LVL 35

Accepted Solution

by:
TimYates earned 450 total points
ID: 11785850
There should be some way to see number of current connections in the SQL Server management console, to verify if this is correct...

And can you post some example code?

Are both instances running on the same database?

With the same version of the drivers?
0
 

Author Comment

by:SweetChastity
ID: 11786167
Its Microsoft SQLServer 2000 Driver for JDBC, I can't see anyway to find more information about it than that.

Our set up is that there are 3 class files that have to be present and compiled to access the database.  Connection, ConnectionPool and PooledConnection.  My class file (ones that work directly with a specified program) import these.  

public void execute( HttpServletRequest request,HttpServletResponse response, ServletContext context ) throws Exception
{
      // Get a database connection from connection pool -- OGA_POOL
      ConnectionPool pool = ( ConnectionPool )context.getAttribute( "OGA_POOL" );
      Connection con = pool.getConnection();

      // create HTTP session
      HttpSession session = request.getSession();

      try
      {
            if ( con != null )
            {
                                                                  String mode = ( String )request.getParameter( "updatemode" );
                                                                  if ( mode == null )                                          {
                                                                        mode = "empty";
                  }

Then I test the mode and do the stuff i need to add/update delete whatever.  We use stored procedures but sometimes I put in sql directly myself until we make a sp to replace it.  I dont' want to put more code up because the boss mentioned about privacy and us not taking code to use elsewhere (in a round about way).

One of the areas where I got this error was
else if ( mode.equals( "searchlastname" ) )
{
      System.err.println( "Get last names from initial" );
      String Letter = ( String )request.getParameter( "NameInitial" );
      CallableStatement cstmt = con.prepareCall( "{? = call  
                             spSSCGetPersonalInfoWithALetter(?)}" );
      cstmt.registerOutParameter( 1, java.sql.Types.INTEGER );
      cstmt.setString( 2, Letter );
      ResultSet rs = cstmt.executeQuery();
      Object[] search_results = parseResultSet( rs );
      returnVal = cstmt.getInt( 1 );
      request.setAttribute( "search_results", search_results );
      rs.close();
}

He has mentioned to us that we need to manually close off the statement and the con manually if we do a direct connection.  There is a problem with stuff not closing properly.  The guy working with me is using direct connections for everything and he has no problems.  He also had no problems running my program.  The first time we demoed the program took so long to run we came to my machine to test it because it would be faster.  I am not sure if the problem is his computer or mine or the server.  

But I want to rule out the beans.  They just seem to be so useful:

Pros I have found:
1. Cuts down on the stored procedures and the number of times I have to access the database
2. I don't have to use functions to convert special characters to pass them between pages, to the database and through URL's (we had a lot of problems with this in the past).
3. URL length isn't a problem when passing a textarea that could be 7000 characters long.
4. Bean is same datatype as field in database so no need to convert/cast types.
5. Persistant in memory; I can access my beans on any page in my program (like for my logged in user)
6. Forms are so much easier.
7. I can access the bean in my class where I am doing all the database work.
8. Client has 30 properties!  Try passing that through a url or hidden fields!

I know that its tricky making sure you load the bean and clear it in the right spots.  I love it tho!  

Even if you can't help with my socket error (because that is his problem, he's the webmaster and more experienced plus the server is on his machine so I can't help him even if I tried) can anyone let me know if there are issues with beans that I should switch to passing them as variables or sessions?  

btw. Tim you have been helpful so far.  I just need to know if this is an issue with my coding, the beans, the class or its the server or driver.  Would I be getting these errors if I never put the beans in?  If I grabbed everything using session.getAttribute and request.getParameter?  Would it be safer just to take out all the beans?  Are beans UNRELIABLE?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

by:haobaba1
ID: 11788347
It sounds to me like you just need to configure your connection pool to use less connections or the database to accept more connections that would depend mostly on how busy the site will be and how much system resources  you have to dedicate to the database server.
0
 

Author Comment

by:SweetChastity
ID: 11790403
My javabeans do no accessing to the database.  I just use it to save properties for my users and clients.  So am I correct in believing that its not the javabeans?  The class files we use are 3 to create the connection, we have ones directly used in porjects that access the connection ones and I'm using javabeans.  Are javabeans a reliable means of storing information in memory?
0
 

Author Comment

by:SweetChastity
ID: 11790655
My javabeans are set to session scope, should they be set to application scope?  I tried that but when I tried to do ClientBean newBean = ( ClientBean )session.getAttribute( "clientbean" ); I would get an error.  Should it be application.getAttribute?  I think I tried that and it didnt' work either.  
0
 
LVL 3

Assisted Solution

by:pat5star
pat5star earned 450 total points
ID: 11818530
In your example code I don't see a con.close() call anywhere. Even with connection pooling (at least everyone I've seen) you still need to call that method. It doesn't actually close the connection but it does return it to the pool.

My guess is that you have 1 or more instances where a connection is made and then never closed/returned. The longer the app runs the more connections are used up until you begin running out of them.

Something else to consider is if any of your database operations are time consuming. I've seen some pools that limit how long a connection can be open before they automatically close them, and if your in the middle of a long running query it may get closed before it finishes.

As to your question about using javabeans for storing info, that is my preferred method. I generally store them in request scope and return them to a jsp page upon each request. If you need the info in the bean to span several pages for that user then I would store it in session scope. If you need the info in the bean to be available to all users over a period of time then you can store it in application scope.

-Pat
0
 

Author Comment

by:SweetChastity
ID: 11819624
On this page:

public void execute( HttpServletRequest request,HttpServletResponse response, ServletContext context ) throws Exception
{
     // Get a database connection from connection pool -- OGA_POOL
     ConnectionPool pool = ( ConnectionPool )context.getAttribute( "OGA_POOL" );
     Connection con = pool.getConnection();

     // create HTTP session
     HttpSession session = request.getSession();

     try
     {
          if ( con != null )
          {
                                                       String mode = ( String )request.getParameter( "updatemode" );
                                                       if ( mode == null )                                   {
                                                            mode = "empty";
               }

which is every java file we make for a project (like for my project I have clients, counsellors and visits and a java for each) at the end of the try after all the catches in the finallly statement it releases the connection.

A user on another forum where I asked for comparison of session variables and beans (for stability) said that beans are complex sessions.  This made perfect sense when I heard it because I import the bean from my JSP pages into the java files using session.getAttribute.  When I told my boss this it seemed to reassure him.

Being a student we often take code from previous projects and alter it to the one we are currently assigned.  I don't like lots of code in my files I don't understand so I try to look it over and figure it out.  We use stored procedures and I've seen that in none of our projects do we close off the callable statements.
CallableStatement cstmt = con.prepareCall( "{? = call spStoredProcedure(?)}" );

So now I am making sure in my project that I close off the cstmt.  Our supervisor came to us months ago complaining that connections were not properly closing and we need to make sure we close off all ResultSet (rs) and Statement (rs) we open.  I think maybe the cstmt might not be closing off as well.

I absolutely love beans!  We had to make ugly nasty functions to replace special characters we passed to the database (they were being saved as a ?) and another one if we passed information with special characters through URLs.  The bean passed special characters to the database without any hassle and, using a generic page we made to display everything in a table for varification, the special characters display with no problems.  That and many other reasons made me very reluctant to give up my beans.
0
 

Author Comment

by:SweetChastity
ID: 11914562
Sorry I haven't posted lately.  The project has been pushed into high gear and I've been so busy I've had dreams where I'm coding :(

I've earned 75 points lately so I'm bumping this up to 300 value and splitting the points.

Thanks for all the help!!
0
 

Author Comment

by:SweetChastity
ID: 11914571
Increasing.
0
 

Author Comment

by:SweetChastity
ID: 11914579
Trying to increase again.
0
 

Author Comment

by:SweetChastity
ID: 11914581
Ok that did it :)

Thanks again guys!
0
 
LVL 3

Expert Comment

by:pat5star
ID: 11916838
Thanks for the points :)

-Pat
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Check out what's been happening in the Experts Exchange community.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

688 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