🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.database
4 messages
4 total messages Started by Oliver Mon, 13 Nov 2006 14:36
speeding up HSQL database
#363
Author: Oliver
Date: Mon, 13 Nov 2006 14:36
32 lines
1948 bytes
Hi

i have in one special project a HSQL database which in principle 
works fine, but my user complained that it gets slow once it has 
only 100 or more entries. Heres the getValueAt method which might
have a performance problem.

@SuppressWarnings
({"ReturnOfNull", "LoopStatementThatDoesntLoop"})
public Object getValueAt(int rowIndex, int columnIndex) {
        Statement stat = null; 
        try {  stat = MyDBConn.createStatement(); }
        catch (SQLException e) {  return null;  }
        String Order = getOrder(SetAscending);  
        String sqlCmd = "SELECT * FROM Res"+Order;  
        if (SetFiltered) sqlCmd = "SELECT * FROM Res WHERE "+sqlCmdFiltered+Order;
        ResultSet rs = null;
        try {  rs = stat.executeQuery(sqlCmd);}
        catch (SQLException e) { return null; }
        try {  while (rs.next())
               {  rs.absolute(rowIndex + 1);
                  if (columnIndex==0) return SpecialFormat(rs.getObject(1));
                  return NumberFormat(rs.getObject(columnIndex + 1));
               }
        } catch (SQLException e) { return null; }
        return "";
}

regards

Oliver
Re: speeding up HSQL database
#364
Author: John Moore (TeamB)
Date: Mon, 13 Nov 2006 19:26
51 lines
2709 bytes
Oliver wrote:
> Hi
> 
> i have in one special project a HSQL database which in principle 
> works fine, but my user complained that it gets slow once it has 
> only 100 or more entries. Heres the getValueAt method which might
> have a performance problem.

Well, I guess first, what is the question..?

Second, I can not find the code you posted in the DX or dbswing source.. 
So.. Where did you get this code..??


John..


> 
> @SuppressWarnings
> ({"ReturnOfNull", "LoopStatementThatDoesntLoop"})
> public Object getValueAt(int rowIndex, int columnIndex) {
>         Statement stat = null; 
>         try {  stat = MyDBConn.createStatement(); }
>         catch (SQLException e) {  return null;  }
>         String Order = getOrder(SetAscending);  
>         String sqlCmd = "SELECT * FROM Res"+Order;  
>         if (SetFiltered) sqlCmd = "SELECT * FROM Res WHERE "+sqlCmdFiltered+Order;
>         ResultSet rs = null;
>         try {  rs = stat.executeQuery(sqlCmd);}
>         catch (SQLException e) { return null; }
>         try {  while (rs.next())
>                {  rs.absolute(rowIndex + 1);
>                   if (columnIndex==0) return SpecialFormat(rs.getObject(1));
>                   return NumberFormat(rs.getObject(columnIndex + 1));
>                }
>         } catch (SQLException e) { return null; }
>         return "";
> }
> 
> regards
> 
> Oliver


-- 
=============================================
TeamB are volunteer helpers.  Please DO NOT REPLY VIA EMAIL!
Post all questions and replies to this newsgroup ONLY
For papers on DataExpress, Applets, JSP, and Web Development go to:
http://www.microps.com/mps/paperFAQ.html
====================================================
Re: speeding up HSQL database
#365
Author: Gillmer J. Derge [TeamB]
Date: Mon, 13 Nov 2006 19:40
25 lines
1920 bytes
Oliver wrote:
> @SuppressWarnings
> ({"ReturnOfNull", "LoopStatementThatDoesntLoop"})

Does this actually work?  I haven't been able to get JBuilder to honor 
@SuppressWarnings annotations.  I also haven't found a good list of 
accepted values anywhere.

>                {  rs.absolute(rowIndex + 1);

My guess is that the slowness is related to this.  My understanding is 
that some (most?) drivers still scroll through the entire result set 
when the absolute method is called.  So, let's say rowIndex is 100. 
Then you're reading through 100 rows of data before you get to the one 
you want.

If you can alter your query so the query only returns the desired row, 
that might help.

It also looks like you could trim down your result set quite a bit. 
You're doing a "SELECT *" but you're only using one column (columnIndex) 
in your code.  A more streamlined query might be faster.

-- 
Gillmer J. Derge [TeamB]
Re: speeding up HSQL database
#366
Author: Oliver
Date: Thu, 16 Nov 2006 12:38
26 lines
1948 bytes
Hi

hey, thanks! 

Now i use a LIMIT x 1 command in order to get only one row, and later the first() method of the ResultSet. That made things really somewhat faster. 

But the main mistake i made in the prepareRenderer method which i didnt show.

Oliver

public Object getValueAt(int rowIndex, int columnIndex) {
        Statement stat = null;
        try {  stat = MyDBConn.createStatement(); }
        catch (SQLException e) {  return null;  }
        String Order = getOrder(SetAscending);
        String sqlCmd = "SELECT LIMIT "+rowIndex +" 1 "+ "* FROM Res"+Order;
        if (SetFiltered) sqlCmd = "SELECT LIMIT "+rowIndex +" 1 "+"* FROM Res WHERE "+sqlCmdFiltered+Order;
        ResultSet rs = null;
        try {  rs = stat.executeQuery(sqlCmd);}
        catch (SQLException e) { return null; }
        try {     rs.first();
                  if (columnIndex==0) return SpecialFormat(rs.getObject(1));
                  return NumberFormat(rs.getObject(columnIndex + 1));
        } catch (SQLException e) { return null; }
   }
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads