Himanshu Khanna

Greenhorn
+ Follow
since Aug 15, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Himanshu Khanna

Hi Prasant ,
I had intiated a thread on batch updates some 3 months back & Java ranch had provided with excellent inputs ..Heres the URL .. http://www.javaranch.com/ubb/Forum3/HTML/001534.html
Hope it helps
Cheers
Himanshu
Hey All ,
Wow ..I say thats the best way of learning
seeking the advice of Best Minds & Experienced Hands ..
Thanks for such an extensive response ...
16 years ago
Thanks Jim for the valuable input ..I was about to change the implementation in my code i.e. moving from new to setLength() ..
Thanks again..
16 years ago
Thanks for the suggestion Bill !!
It wud be much better indeed to use setLength() rather than reintializing ..
16 years ago
Hi All ,
I am using StringBuffer for building a row to be written to a file . After writing one row to the file I need empty the StringBuffer object so as to use it again.
I am using strBuf = new StringBuffer() to do this .
Another way possible is delete method of StringBuffer (I think but haven't used ever)
Please advice which way is better keeping issues of performance & memory in mind.
Thanks
16 years ago
Hi all & Hello Jamie ,
I think this maybe a bit ofa help on the batch rollback issue(in case of SQLException) -
maybe the class BatchUpdateException needs to be explored .The API documentation does mention about this Exception class though I tried to catch this particular Exception,it wasn't caught ..
[CODE]
for(int i = 0 ; i<5000 ; i++)<br /> {<br /> try<br /> {<br /> // inducing error after 20 elements addition to batch<br /> if(ctr == 20)<br /> {<br /> ps.setInt(1,2000000);<br /> }<br /> else<br /> {<br /> ps.setInt(1,i);<br /> }<br /> ps.setString(2,"Joe Blo");<br /> ctr++;<br /> ps.addBatch();<br /> if(ctr == 250 )<br /> { insertCount=ps.executeBatch();<br /> con.commit(); <br /> ctr = 0;<br /> } <br /> }<br /> catch(BatchUpdateException bue)<br /> {<br /> ctr = 0;<br /> con.commit(); <br /> int [] test = bue.getUpdateCounts() ;<br /> System.out.println("BATCH UPDATE EXCEPTION");<br /> System.out.println("The no of rows inserted are-->" + test.length);
}
catch(SQLException sql)
{
System.out.println("CTR is-->" + ctr);
}
[CODE]
The staetment "BATCH UPDATE EXCEPTION" is not printed instead "CTR is-->" is printed ..can't understand why ?
Hi Jamie,
Well , haven't tried the Exceptions table suggestion ..don't know exactly how to go abt doing that ..please give some tips how to go abt doing that ..
Nope haven't explored jdk1.4 ..proj. specification is 1.3 , so that option is ruled out ..
Kind of struck !!
This is a limitation of using batches it seems ..they're appropriate only if U r generating the P Key ..
Thanks again Jamie
Hi Jamie ,
I have Oracle as a DB so please give Ur valuable tips to achive the desired result !!
I am also dealing with statistical data ..but I can't have my own primary key (auto generated) as the nature of the proj. is such that I need to have one of the supplied data as primary key (infact its a composite primary key ..anyway).I need to keep a track of the offending recs & store them in a error CSV
Thanks again
Himanshu
Hi jamie ,
Trouble of a new Kind !!!
I am inserting records in the DB using batches of ,say, 1000.
Imagine the parameter to the 500 statement in the Batch has the Primary key value duplicated .This would throw a SQL Exception .
The trouble I am facing is that due to that 500th record , my next 500 records are rolled back too which is not the requirement.
If a particular record is having an already existing Primary key , I need to write it to an error file than proceed to the next record ..
Can you think of a workaround for this specific requirement ?
Thanks for Ur invaluable suggestions Jamie !!
Thanks Again , Jamie ..
Following Ur advice , I am testing now with batches of 50 ..and the program sure has fastened up !!
Wud keep on increasing the batche size .
In fact after reading Ur response , I straight away set the batch for 1000 :-) but somehow the program slowed down ( I am sure the my program's bug ).
I have seen an increase of 40 % in performance with size of 50 ..
will surely tell u abt the effectiveness increase of the inflated batch sizes..
Thanks Jamie !!
Hi Jamie ,
I tried the Batch insert but it didn't make much of a differance on the speed of record insertion ..maybe there was something wrong in my implementation ..
cstmtTry.setString(1,strEventId);
::::::::::::::::::::::::::
..so..on
..
cstmtTry.setInt(11,nAmnt);
cstmtTry.setString(12,strRecFrm);
cstmtTry.setString(13,strCntctNo);
if (debug) System.out.println("Going for ExecuteUpdate");
cstmtTry.addBatch();
ctr++;
if(ctr == 10)
{
ctr = 0;
insertCount=cstmtTry.executeBatch();
con.commit();
cstmtTry.clearParameters();
}
I am inserting in a batch of 10 ..What I wanted to know was that could the statement " cstmtTry.clearParameters() " be slowing things down for I couldn't figure out why the execution time increased instead of decreasing when I implemented the batch insert ??
One more thing , is there a limit on the no. of batches that I accumulate before executing ?
Thanks Once Again Jamie ! I will try to implement the batch update today & lets see.
One more thing , Could U tell me wether the kind of Oracle driver I use for establishing connection makes a differance on performance i.e. are oci & thin clients the same performance wise or is thin faster ?
I am sorry I started another thread where I have asked the same ques. abt the drivers ..(I posted the ques yesterday)
Hey , it may be a case of Lower case / Upper case .Please check the names of the package & the function have the same case in Oracle as well as Ur java code
try connecting it using a thin client ..
con = DriverManager.getConnection("jdbc racle:thin:@19.68.16.15:1521:default", "scott","tiger");
replace the I.P , Port no. , DB name , username ,�@pwd according to ur needs
find following dummy code snippet if useful to u..
String strFunName = {?=call(?....?)}
where first ? is for return value and
second ? is for parameter u passed it can be any no.
now call the prepareCall method of con like in following steps
1) CallableStatement cStmt = con.prepareCall(strFunName );
2) cStmt.setXXX(parameterValue);
3) cStmt.registerOutParameter(1, Types.NUMERIC)
4) cStmt.executeUpdate();
5) if the return type is int..
int value = cStmt.getInt(1);
thats it