Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Stored Procedure performance issue...

Status
Not open for further replies.

cnoel

Programmer
Jul 16, 2001
4
US
Hi all..
I have recently developed an update procedure for our imaging system using JDBC. The procedure performed updates on approx 13,000 records, and took just over 13 hours. This equates to 1 transactions per second... which is not acceptable for future use. My initial suspicions target the db logging scheme, but thought i would touch base here for additional ideas. The code follows below. The app runs well until it hits the routine to perform the updates (see 'update the nines'), then it slows considerably. We do have roll forward recovery enabled with 1 meg log file size.
Any suggestions would be appreciated.
Thanks
Curtis

/**
* JDBC Stored Procedure DB2ADMIN.JNinesUpdate
*/

import java.sql.*; // JDBC classes

public class JNinesUpdate
{
public static void JNinesUpdate () throws SQLException, Exception
{
// Get connection to the database

Connection con = DriverManager.getConnection("jdbc:default:connection");

// Variable declarations

PreparedStatement delstmt = null;
PreparedStatement ninesstmt = null;
PreparedStatement matchesstmt = null;
PreparedStatement updatestmt = null;
PreparedStatement sortstmt = null;
PreparedStatement insertstmt = null;
PreparedStatement cycle = null;

ResultSet rs = null;
ResultSet ud = null;
int x = 0;

String tablename = "";
String tablenumber = "";
String ninessql = "";
String deletesql="";
String matchessql="";
String updatesql="";
String sortsql = "";
String insertsql = "";
String cyclesql = "";

// housekeeping
deletesql = "DELETE FROM DB2ADMIN.TPRESORT;";
delstmt = con.prepareStatement( deletesql );
delstmt.executeUpdate();

deletesql = "DELETE FROM DB2ADMIN.TNINES;";
delstmt = con.prepareStatement( deletesql );
delstmt.executeUpdate();


deletesql = "DELETE FROM DB2ADMIN.TMATCHES;";
delstmt = con.prepareStatement( deletesql );
delstmt.executeUpdate();

// find the nines..

for (x=59; x<=106; x++)
{
tablenumber = String.valueOf(x);

if (x!=66 && x!=74 && x!=82 && x!=90 && x!=98 && x!=102)
{
if (x<100)
{
tablename = &quot;DB2ADMIN.AVT000&quot; + tablenumber;
}
else
{
tablename = &quot;DB2ADMIN.AVT00&quot; + tablenumber;
};

ninessql = &quot;INSERT INTO DB2ADMIN.TNINES (DCN,ITEMID,LOCATION) SELECT &quot;
+ tablename + &quot;.ATTRIBUTE00120, &quot;
+ tablename + &quot;.ITEMID, &quot;
+ tablenumber
+ &quot; FROM &quot; + tablename
+ &quot; WHERE &quot;
+ tablename + &quot;.ATTRIBUTE00114 = '9999999999';&quot;;

ninesstmt = con.prepareStatement( ninessql );
ninesstmt.executeUpdate();
}
}

// find the matches for nines...

for (x=59; x<=106; x++)
{
tablenumber = String.valueOf(x);
tablenumber.trim();

if (x!=66 && x!=74 && x!=82 && x!=90 && x!=98 && x!=102)
{
if (x<100)
{
tablename = &quot;DB2ADMIN.AVT000&quot; + tablenumber;
}
else
{
tablename = &quot;DB2ADMIN.AVT00&quot; + tablenumber;
};

matchessql = &quot;INSERT INTO DB2ADMIN.TPRESORT (DCN,LOCATION,ITEMID,POLICYNUMBER,LASTUPDATED) &quot;
+ &quot;SELECT DB2ADMIN.TNINES.DCN, &quot;
+ &quot;DB2ADMIN.TNINES.LOCATION, &quot;
+ &quot;DB2ADMIN.TNINES.ITEMID, &quot;
+ tablename + &quot;.ATTRIBUTE00114, &quot;
+ tablename + &quot;.ATTRIBUTE00119 &quot;
+ &quot;FROM DB2ADMIN.TNINES &quot;
+ &quot;INNER JOIN &quot; + tablename
+ &quot; ON DB2ADMIN.TNINES.DCN = &quot; + tablename + &quot;.ATTRIBUTE00120 &quot;
+ &quot;WHERE (((&quot; + tablename + &quot;.ATTRIBUTE00114) <> '9999999999'));&quot;;

matchesstmt = con.prepareStatement( matchessql );
matchesstmt.executeUpdate();
}
}
// sort the matches and write them to the sorted table;

sortsql = &quot;SELECT DCN, &quot;
+ &quot;POLICYNUMBER, &quot;
+ &quot;LOCATION, &quot;
+ &quot;LASTUPDATED, &quot;
+ &quot;ITEMID &quot;
+ &quot;FROM DB2ADMIN.TPRESORT &quot;
+ &quot;ORDER BY LASTUPDATED ASC;&quot;;

sortstmt = con.prepareStatement( sortsql );
rs = sortstmt.executeQuery();

while (rs.next())
{

insertsql = &quot;INSERT INTO DB2ADMIN.TMATCHES (DCN,POLICYNUMBER,LOCATION,LASTUPDATED,ITEMID) &quot;
+ &quot;VALUES ('&quot; + rs.getString(1)
+ &quot;','&quot; + rs.getString(2)
+ &quot;',&quot; + rs.getString(3)
+ &quot;,'&quot; +rs.getString(4)
+ &quot;','&quot; +rs.getString(5)
+ &quot;');&quot;;

insertstmt = con.prepareStatement ( insertsql );
insertstmt.executeUpdate();

}


//update the nines

for (x=59; x<=106; x++)
{
tablenumber = String.valueOf(x);

if (x!=66 && x!=74 && x!=82 && x!=90 && x!=98 && x!=102)
{
if (x<100)
{
tablename = &quot;DB2ADMIN.AVT000&quot; + tablenumber;
}
else
{
tablename = &quot;DB2ADMIN.AVT00&quot; + tablenumber;
};

cyclesql = &quot;SELECT FROM DB2ADMIN.TMATCHES WHERE LOCATION = &quot; + x;

cycle = con.prepareStatement( sortsql );
ud = sortstmt.executeQuery();

while (ud.next())
{

updatesql = &quot;UPDATE &quot; + tablename
+ &quot; SET (&quot; + tablename + &quot;.ATTRIBUTE00114, &quot;
+ tablename + &quot;.ATTRIBUTE00119) = &quot;
+ &quot;('&quot; + ud.getString(2) +&quot;', CURRENT DATE) &quot;
+ &quot;WHERE (((&quot; + tablename + &quot;.ATTRIBUTE00114)='9999999999')&quot;
+ &quot;AND ((&quot; + tablename + &quot;.ATTRIBUTE00120)='&quot; + ud.getString(1) + &quot;'));&quot;;

updatestmt = con.prepareStatement ( updatesql );
updatestmt.executeUpdate();

}


}
}

// endgame

if (con != null) con.close();

}
}
 
May I ask you do u schedule the stored procudure to run daily?
If so, can you tell me how to schedule java stored procedure please? I don't know how to do this and I urgently need to do this.....
Thanks a lot!
 
with a tad bit of embarassment, I have located the flaw in execution. Being a little quick on the cut & paste caused me to miss a variable change

cyclesql = &quot;SELECT FROM DB2ADMIN.TMATCHES WHERE LOCATION = &quot; + x;

cycle = con.prepareStatement( sortsql );
ud = sortstmt.executeQuery();

while (ud.next())





cycle = con.prepareStatement( sortsql );

should have been

cycle = con.prepareStatement( cyclesql );

this caused the proc to loop through the entire recordset intstead of a filtered verion. probably added 50,000 additional i/o actions, which might have just a little something to do with the miserable performance.

Justyn,
The jobs are set up through the script center, where you can define and schedule your scripts, I have not explicity performed this with stored procedures, only backups.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top