资源描述:
《Introduction to JDBC外文资料翻译.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、IntroductiontoJDBCThisdocumentillustratesthebasicsoftheJDBC(JavaDatabaseConnectivity)API(ApplicationProgramInterface).Here,youwilllearntousethebasicJDBCAPItocreatetables,insertvalues,querytables,retrieveresults,updatetables,createpreparedstatements,performtransa
2、ctionsandcatchexceptionsanderrors.ThisdocumentdrawsfromtheofficialSuntutorialonJDBCBasics.OverviewEstablishingaConnectionCreatingaJDBCStatementCreatingaJDBCPreparedStatementExecutingCREATE/INSERT/UPDATEStatementsExecutingSELECTStatementsNotesonAccessingResultSet
3、TransactionsHandlingErrorswithExceptionsSampleCodeandCompilationInstructionsOverviewCall-levelinterfacessuchasJDBCareprogramminginterfacesallowingexternalaccesstoSQLdatabasemanipulationandupdatecommands.TheyallowtheintegrationofSQLcallsintoageneralprogrammingenv
4、ironmentbyprovidinglibraryroutineswhichinterfacewiththedatabase.Inparticular,JavabasedJDBChasarichcollectionofroutineswhichmakesuchaninterfaceextremelysimpleandintuitive.Hereisaneasywayofvisualizingwhathappensinacalllevelinterface:YouarewritinganormalJavaprogram
5、.Somewhereintheprogram,youneedtointeractwithadatabase.Usingstandardlibraryroutines,youopenaconnectiontothedatabase.YouthenuseJDBCtosendyourSQLcodetothedatabase,andprocesstheresultsthatarereturned.Whenyouaredone,youclosetheconnection.Suchanapproachhastobecontrast
6、edwiththeprecompilationroutetakenwithEmbeddedSQL.Thelatterhasaprecompilationstep,wheretheembeddedSQLcodeisconvertedtothehostlanguagecode(C/C++).Call-levelinterfacesdonotrequireprecompilationandthusavoidsomeoftheproblemsofEmbeddedSQL.Theresultisincreasedportabili
7、tyandacleanerclient-serverrelationship.EstablishingAConnectionThefirstthingtodo,ofcourse,istoinstallJava,JDBCandtheDBMSonyourworkingmachines.SincewewanttointerfacewithanOracledatabase,wewouldneedadriverforthisspecificdatabaseaswell.Fortunately,wehavearesponsible
8、administratorwhohasalreadydoneallthisforusontheLelandmachines.Aswesaidearlier,beforeadatabasecanbeaccessed,aconnectionmustbeopenedbetweenourprogram(client)andthedatab