Which way will give me better performance?
4 posts in topic
Flat View  Flat View

Posted By:   Parag_Bharambe
Posted On:   Thursday, July 12, 2001 01:05 AM

Hello Friends,
I am using JDBC and DBMS is Oracle. I need to retrive data from Oracle. I can do it in Two ways
1) Store the result of queries (Using java.sql.Statement Object) into Different Resultset and Use these Resultset in BusinessProcess Logic .
2) Store the result into Collection like Vector, Hashtable and use them in BusinessProcess Logic.
My DBMS has millions of record, which I will nedd to Go through.
Which way is more effieient to do?

Re: Which way will give me better performance?

Posted By:   Aron_Tunzi  
Posted On:   Thursday, July 12, 2001 11:56 PM

The second solution is better because you separe the business layer to the jdbc layer. An other reason is that the application is safetly. Think about the ResultSet and the Statement objects ... wath happen to the ResultSet when the connection is closed? What happen to the ResultSet when you execute an other SQL query with the same Statement? And so on...

I will suggest you to put each object in a LinkedList, that is a Collection as the Vector class but much better for save a big number or Object. With a LinkedList object you can do the same:

ListIteretor iter = linkedListoObject.listIterator();

and than you can iterate through your object ...





That is a good solution.

Bye bye and for other problems I'm ever here, Aron

Re: Which way will give me better performance?

Posted By:   Anonymous  
Posted On:   Thursday, July 12, 2001 10:50 PM

The answer really depends on exactly what your app needs to do, although I'm not sure how you plan to put the data into another ResultSet unless it something like a cached ResultSet.

However, that may all be moot. People are often derided when they say redesign your app to deal with fewer records at a time, but you have a very real issue here of how much memory is available. I've seen apps in the past chug away trying to read all the data in one pass, only to eventually die with an "out of memory" error.

Re: Which way will give me better performance?

Posted By:   Aron_Tunzi  
Posted On:   Thursday, July 12, 2001 02:55 AM

I think that if you want separate the business layer for the persistent layert (jdbc layer) the second solution is the better.

I done the same. For each table in the DB i programed a class with all db-attributes(**) and when I must search more record I programed a finder class that returned me a LinkedList. In this method i execute a Statement,iterate the ResultSet, create an object(**), puit the object in the LinkedList. and returned the LinkedList.

public LinkedList findOrderByMember(Long id) throws PersistentException, ExceptionDataNotFound
LinkedList resultVector = new LinkedList();
Order order = null;

String qry = "SELECT * FROM ORDER WHERE MEMBER = " + id;
Statement stmt = this.pl.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet result = stmt.executeQuery(qry);
boolean found = false;

while (result.next())
found = true;

Long price = Converter.getLong(result.getBigDecimal(1));
Long pieces = Converter.getLong(result.getBigDecimal(2));
String productId = result.getString(3);
String productName = result.getString(4);

order = new Order(pl, id, piece, productId, productName);

if (!found)
throw new ExceptionDataNotFound(PersistentException.RECORD_NOT_FOUND);

return resultVector;
catch (SQLException ex)
System.out.println("In PersistentObjectFinder.findOrderByMember(): ");

System.out.println("SQL State: " + ex.getSQLState());
System.out.println("Error Code: " + ex.getErrorCode());

throw new ExceptionDataNotFound(PersistentException.RECORD_NOT_FOUND);


Bye Aron

Re: Which way will give me better performance?

Posted By:   bharat_khillari  
Posted On:   Thursday, July 12, 2001 02:11 AM

Second way is best.
About | Sitemap | Contact