java JDBC 外文翻译 外文文献 英文文献Word文档下载推荐.docx
《java JDBC 外文翻译 外文文献 英文文献Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《java JDBC 外文翻译 外文文献 英文文献Word文档下载推荐.docx(20页珍藏版)》请在冰豆网上搜索。
Performanceisusuallyconsideredanissueattheendofadevelopmentcyclewhenitshouldreallybeconsideredfromthestart.Often,ataskcalled"
performancetuning"
isdoneafterthecodingiscomplete,andtheenduserofaprogramcomplainsabouthowlongittakestheprogramtocompleteaparticulartask.Thenetresultofwaitinguntiltheendofthedevelopmentcycletoconsiderperformanceincludestheexpenseoftheadditionaltimerequiredtorecodeaprogramtoimproveitsperformance.It'
smyopinionthatperformanceissomethingthatisbestconsideredatthestartofaproject.
WhenitcomestoperformanceissuesconcerningJDBCprogrammingtherearetwomajorfactorstoconsider.ThefirstistheperformanceofthedatabasestructureandtheSQLstatementsusedagainstit.ThesecondistherelativeefficiencyofthedifferentwaysyoucanusetheJDBCinterfacestomanipulateadatabase.
Intermsofthedatabase'
sefficiency,youcanusetheEXPLAINPLANfacilitytoexplainhowthedatabase'
soptimizerplanstoexecuteyourSQLstatements.Armedwiththisknowledge,youmaydeterminethatadditionalindexesareneeded,orthatyourequireanalternativemeansofselectingthedatayoudesire.
Ontheotherhand,whenitcomestousingJDBC,youneedtoknowaheadoftimetherelativestrengthsandweaknessesofusingauto-commit,SQL92syntax,andaStatementversusaPreparedStatementversusaCallableStatementobject.Inthischapter,we'
llexaminetherelativeperformanceofvariousJDBCobjectsusingexampleprogramsthatreporttheamountoftimeittakestoaccomplishagiventask.We'
llfirstlookatauto-commit.Next,we'
lllookattheimpactoftheSQL92syntaxparser.Thenwe'
llstartaseriesofcomparisonsoftheStatementobjectversusthePreparedStatementobjectversustheCallableStatementobject.Atthesametimewe'
llalsoexaminetheperformanceoftheOCIversustheThindriverineachsituationtoseeif,asOracle'
sclaims,thereisasignificantenoughperformancegainwiththeOCIdriverthatyoushoulduseitinsteadoftheThindriver.Forthemostpart,ourdiscussionswillbebasedontimingdatafor1,000insertsintothetestperformancetableTESTXXXPERF.Thereareseparateprogramsforperformingthese1,000insertsusingtheOCIdriverandtheThindriver.
Theperformancetestprogramsthemselvesareverysimpleandareavailableonlinewiththerestoftheexamplesinthisbook.However,forbrevity,I'
llnotshowthecodefortheexamplesinthischapter.I'
llonlytalkaboutthem.Althoughtheactualtimingvalueschangefromsystemtosystem,theirrelativevalues,orratiosfromonesystemtoanother,remainconsistent.ThetimingsusedinthischapterweregatheredusingWindows2000.Usingobjectivedatafromtheseprogramsallowsustocometofactualconclusionsonwhichfactorsimproveperformance,ratherthanrelyingonhearsay.
I'
msureyou'
llbesurprisedattherealityofperformancefortheseobjects,andIhopeyou'
llusethisknowledgetoyouradvantage.Let'
sgetstartedwithalookatthetestingframeworkusedinthischapter.
ATestingFramework
Forthemostpart,thetestprogramsinthischapterreportthetimingsforinsertingdataintoatable.IpickedanINSERTstatementbecauseiteliminatestheperformancegainofthedatabaseblockbuffersthatmayskewtimingsforanUPDATE,DELETE,orSELECT.
Thetesttableusedintheexampleprogramsinthischapterisasimplerelationaltable.IwantedittohaveaNUMBER,asmallVARCHAR2,alargeVARCHAR2,andaDATEcolumn.TableTESTXXXPERFisdefinedas:
createtableTestXXXPerf(
idnumber,
codevarchar2(30),
descrvarchar2(80),
insert_uservarchar2(30),
insert_datedate)
tablespaceuserspctfree20
storage(initial1Mnext1Mpctincrease0);
altertableTestXXXPerf
addconstraintTestXXXPerf_Pk
primarykey(id)
usingindex
Theinitialextentsizeusedforthetablemakesitunlikelythatthedatabasewillneedtotakethetimetoallocateanotherextentduringtheexecutionofoneofthetestprograms.Therefore,extentallocationwillnotimpactthetimings.Giventhisbackground,youshouldhaveacontexttounderstandwhatisdoneineachsectionbyeachtestprogram.
Auto-Commit
Bydefault,JDBC'
sauto-commitfeatureison,whichmeansthateachSQLstatementiscommittedasitisexecuted.IfmorethanoneSQLstatementisexecutedbyyourprogram,thenasmallperformanceincreasecanbeachievedbyturningoffauto-commit.
Let'
stakealookatsomenumbers.Table19-1showstheaveragetime,inmilliseconds,neededtoinsert1,000rowsintotheTESTXXXPERFtableusingaStatementobject.Thetimingsrepresenttheaveragefromthreerunsoftheprogram.Bothdriversexperienceapproximatelya