Thanks for the welcome
I've surfed around here a bit but haven't participated up til now.
Well the set up we have for projects is that the students (I myself being one) code the
JSP pages. The webmaster has made 3 class files: ConnectionPool.java, PooledConnection.java and Connection.java. These 3 classes work to create the connection to the database.
We have sort of a base template we use for our projects. Like News program had New.java. It creates a vector ResultSet and an Object ResultSet then has an execute ("public void execute( HttpServletRequest request,HttpServletResponse response, ServletContext context ) throws Exception"). Inside here is:
// Get a database connection from connection pool -- POOL
ConnectionPool pool = ( ConnectionPool )context.getAttribute( "POOL" );
Connection con = pool.getConnection();
// create HTTP session
HttpSession session = request.getSession();
After this we have a try and catch set up. Within the try is where we students work. The rest of the code is all set up and we just copy an old file and alter the try. Within here we request a mode from our page and then we
test for it. So my project has if (mode.equals(addclient)).
Within the if/else if statments we can create a CallableStatement if we have a stored procedure or we use a Statement until the stored procedure can be created for us. It is pretty simple for us to create a project but we have no real idea what's going on in the
java files he's made to see if the connections are all being closed properly.
One thing we do though is if we produce a listbox, we make a seperate .jsp page and connect through there. The webmaster came to us a couple months back and told us to make sure we were closing everything off properly, that some sockets or connections weren't closing properly. There is a language barrier and its very difficult to get some standards set up because he seems to change his mind with different students and different projects (like one guy now is not using those 3 java connection files, he's doing all his connections directly with no stored procedures). But I want to be sure I'm closing everything so I want to check here, which of these need to be manually closed?
ResultSet rs with rs.close();
Statement stmt with stmt.close();
CallableStatement cstmt with cstmt.close();
We do the first two but I am wondering if we need to close the CallableStatement (which I have never done or seen done in any of our projects).
In my beans I am only importing the following:
package edu.admin.services;
import java.sql.*;
import java.util.*;
import java.lang.*;
There is no direct connection to the database, nothing to do with the database at all. All it is is properties with gets and sets, one that reinitializes everything to 0 or "" and one that takes the object search_results generated from the database class file (Clients.java, News.java, PhoneBook.java, etc) and sets all the properties.
Now in my Clients.java file I am importing import edu.admin.services.ClientBean;
and using ClientBean newBean = ( ClientBean )session.getAttribute( "clientbean" ); to access the information I have stored in my bean, could this be a problem?
Honestly I love working with the beans. My clients have close to 50 properties that are viewed and updated across multiple pages within my project. We have had problems with special characters being passed between pages, especially through URLs, and to the database. We've had to create huge functions to replace any special character we can think of, resorting to replacing & with AMP; and other ugly messy handling functions. When looking into the database if we didn't use these functions all the special characters were stored as ? but the database took the special characters in a bean and saved em just like they were, ie @#$%^&*!. No problem.
I am very reluctant to remove the beans. I've been able to take 6 pages of code to add a client and reduce it to 3. I've been able to seperate interface from business logic. There is no way I could explain that to my supervisor in a way he would understand. But since I'm the only one in the office who's ever worked with beans I have no clue as to some of the issues that they can cause in development.
Are there any problems with beans? Are they less reliable than session variables? Is there a way they can easily lose their information? My user logins in and creates a bean and if the bean dies in the middle of the program the user's screwed and so am I. Is there anything to do with beans that I am unaware of?
P.S. Thanks for replying Jules! It was terribly frustrating today when we demo'd for over an hour with my code working perfectly before socket errors made it crap out. Then the guy says its my code but it was fine and we saw those pages load within the that demo. He said my code is unreliable and he blames the beans yet I brought him 6 pages of tomcat screenshots showing him the socket errors. He still thinks its my code