Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

heap memory

Thread view: 
Andrea - 24 Feb 2007 12:22 GMT
Hi all,
I've a jsp-form which inquiry a database with a sql-query, and obtain a
recordset placed in a type-Vector variable; all working fine when I expose
this result in a html-page.
Now I need to expose same result in a Excel worksheet, so now my jsp contain
this code string:
  response.setContentType("application/vnd.ms-excel");
  response.setHeader("Content-disposition",
"attachment;filename=report_wiz.xls");
All working fine until (I suppose) Vector extracted is "light", but if it's
"heavy" in its dimension then I have an error page instead my xls sheet with
data inside.
I can expand my java-container with this parameter:
 -Xms512m -Xmx512m
but could be not sufficient!
So, there is a way to intercept Vector-dimension? If yes, I can check this
before pass it to Excel-page, and if it's too big I can throw an alert like
"too much fields or too much rows extracted" to my users, instead a bad
error-page.
Thanks in advance
JFM
Daniel Pitts - 24 Feb 2007 18:24 GMT
> Hi all,
> I've a jsp-form which inquiry a database with a sql-query, and obtain a
[quoted text clipped - 17 lines]
> Thanks in advance
> JFM

First, you don't tell us what database interface you are using, JDBC?
iBATIS? Hibernate?

Some data access frameworks allow you to use lazy loading, and/or row
handling. This allows you to only load into memory what you need.

Alternatively, you can add a new SQL query that is like your original
query, but returns the number of rows.

Original: SELECT a, b, c FROM table_a WHERE a=b+1 <etc...>
Counting: SELECT COUNT(*) FROM table_a WHERE a=b+1 <etc...>
Andrea - 25 Feb 2007 08:20 GMT
> > Hi all,
> > I've a jsp-form which inquiry a database with a sql-query, and obtain a
[quoted text clipped - 29 lines]
> Original: SELECT a, b, c FROM table_a WHERE a=b+1 <etc...>
> Counting: SELECT COUNT(*) FROM table_a WHERE a=b+1 <etc...>

Hi Daniel,
sorry, I have a JDBC interface to an Oracle database.
And about second suggestion, number and type of field selected can be
changed at each inqury, so a "select count(*)" not solve my trouble. Two
example: I can exctract 50000 rows with only a numeric field (and this works
fine), or 20000 rows composed by twenty fields (some numeric, some
varchar)... and is exactly this last event which cause my trouble.
Two seconds ago, I find this method:
  vector.capacity()
now I go to search documentation about in order to see if it can help me; do
you know if this method could be ad-hoc for my problem?
Thanks again
JFM
Daniel Pitts - 25 Feb 2007 09:07 GMT
> > > Hi all,
> > > I've a jsp-form which inquiry a database with a sql-query, and obtain a
[quoted text clipped - 49 lines]
> Thanks again
> JFM

If you have control of the code that adds the data into the Vector,
change it to instead process it as a stream of rows!  Many people find
it easier conceptually to deal with a Vector, however, often times you
can minimize memory requirements by changing your algorithms to
stream.

Well, hope this helps.
Daniel.
Andrea - 25 Feb 2007 19:04 GMT
> > > > Hi all,
> > > > I've a jsp-form which inquiry a database with a sql-query, and obtain a
[quoted text clipped - 58 lines]
> Well, hope this helps.
> Daniel.

Hi Daniel,
thanks for your suggestion, very interesting!
Please, have you an example about this method? Or can you tell me an url
where I can find documentation about it?
Thanks again
JFM
Daniel Pitts - 25 Feb 2007 19:31 GMT
> > > "Daniel Pitts" <googlegrou...@coloraura.com> ha scritto nel
>
[quoted text clipped - 77 lines]
> Thanks again
> JFM

http://www.google.com

<End of line>
Patricia Shanahan - 25 Feb 2007 20:22 GMT
...
>> If you have control of the code that adds the data into the Vector,
>> change it to instead process it as a stream of rows!  Many people find
[quoted text clipped - 11 lines]
> Thanks again
> JFM

Here's a snippet from one of my programs:

    Connection con = Connect.getConnection(dbName);
    con.setAutoCommit(false);
    Statement st = con.createStatement();
    st.setFetchSize(1000);
    ResultSet result = st.executeQuery(getData);
    while (result.next()) {
      count(result.getInt(1), result.getDouble(2), result.getBoolean(3));
    }

(Don't assume this is good style - I'm just learning combining Java and
database. It works with PostgreSQL.)

The main issue seems to be to design the query so that the results are
in an order in which you can process them. If you are not currently
processing the Vector in index order, you may need to add/change an
"ORDER BY" clause in the query.

Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.