|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于一个大型项目,如果用java来作,可能需要9个月,并且可能需要翻阅10本以上的书,但如果用ruby来作,3个月,3本书就足够了,而.net也不过3,4本书足以,这就是区别。
Thenameoftheclassthatimplementsjava.sql.DriverinMySQLConnector/Jiscom.mysql.jdbc.Driver.Theorg.gjt.mm.mysql.Driverclassnameisalsousabletoremainbackwards-compatiblewithMM.MySQL.Youshouldusethisclassnamewhenregisteringthedriver,orwhenotherwiseconfiguringsoftwaretouseMySQLConnector/J.
TheJDBCURLformatforMySQLConnector/Jisasfollows,withitemsinsquarebrackets([,])beingoptional:
jdbc:mysql://[host][,failoverhost...][:port]/[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
Ifthehostnameisnotspecified,itdefaultsto127.0.0.1.Iftheportisnotspecified,itdefaultsto3306,thedefaultportnumberforMySQLservers.
Startingwithversion3.0.12and3.1.2,Connector/Jsupportsmultiplehostswithports,separatedbycommas:
jdbc:mysql://[host:port],[host:port].../[database][?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
Ifthedatabaseisnotspecified,theconnectionwillbemadewithnocurrentdatabase.Inthiscase,youwillneedtoeithercallthesetCatalog()methodontheConnectioninstance,issueaUSEdbnamequeryorfully-specifytablenamesusingthedatabasename(i.e.SELECTdbname.tablename.colnameFROMdbname.tablename...)inyourSQL.Notspecifyingthedatabasetouseuponconnectionisgenerallyonlyusefulwhenbuildingtoolsthatworkwithmultipledatabases,suchasGUIdatabasemanagers.
MySQLConnector/Jhasfail-oversupport.Thisallowsthedrivertofail-overtoanynumberof"slave"hostsandstillperformread-onlyqueries.Fail-overonlyhappenswhentheconnectionisinanautoCommit(true)state,becausefail-overcannothappenreliablywhenatransactionisinprogress.MostgoodapplicationserversandconnectionpoolssetautoCommittotrueattheendofeverytransaction/connectionuse.Thefail-overfunctionalityhasthefollowingbehavior:IftheURLproperty"autoReconnect"isfalse:Failoveronlyhappensatconnectioninitialization,andfailbackoccurswhenthedriverdeterminesthatthefirsthosthasbecomeavailableagainIftheURLproperty"autoReconnect"istrue:Failoverhappenswhenthedriverdeterminesthattheconnectionhasfailed(beforeeveryquery),andfallsbacktothefirsthostwhenitdeterminesthatthehosthasbecomeavailableagain(afterqueriesBeforeRetryMasterquerieshavebeenissued).Ineithercase,wheneveryouareconnectedtoa"failed-over"server,theconnectionwillbesettoread-onlystate,soqueriesthatwouldmodifydatawillhaveexceptionsthrown(thequerywillneverbeprocessedbytheMySQLserver).
YoumayspecifyadditionalpropertiestotheJDBCdriver,eitherbyplacingtheminajava.util.PropertiesinstanceandpassingthatinstancetotheDriverManagerwhenyouconnect,orbyaddingthemtotheendofyourJDBCURLasname-valuepairs.Thefirstpropertyneedstobepreceededwitha?character,andadditionalname-valuepairpropertiesareseparatedbyan&character.Theproperties,theirdefinitionsandtheirdefaultvaluesarecoveredinthefollowingtable:
Table2.1.ConnectionProperties
Connection/AuthenticationuserTheusertoconnectasNopasswordThepasswordtousewhenconnectingNosocketFactoryThenameoftheclassthatthedrivershoulduseforcreatingsocketconnectionstotheserver.Thisclassmustimplementtheinterfacecom.mysql.jdbc.SocketFactoryandhavepublicno-argsconstructor.Nocom.mysql.jdbc.StandardSocketFactoryconnectTimeoutTimeoutforsocketconnect(inmilliseconds),with0beingnotimeout.OnlyworksonJDK-1.4ornewer.Defaultsto0.No0socketTimeoutTimeoutonnetworksocketoperations(0,thedefaultmeansnotimeout).No0useConfigsLoadthecomma-delimitedlistofconfigurationpropertiesbeforeparsingtheURLorapplyinguser-specifiedproperties.TheseconfigurationsareexplainedintheConfigurationsofthedocumentation.NointeractiveClientSettheCLIENT_INTERACTIVEflag,whichtellsMySQLtotimeoutconnectionsbasedonINTERACTIVE_TIMEOUTinsteadofWAIT_TIMEOUTNofalsepropertiesTransformAnimplementationofcom.mysql.jdbc.ConnectionPropertiesTransformthatthedriverwillusetomodifyURLpropertiespassedtothedriverbeforeattemptingaconnectionNouseCompressionUsezlibcompressionwhencommunicatingwiththeserver(true/false)?Defaultstofalse.NofalseHighAvailabilityandClusteringautoReconnectShouldthedrivertrytore-establishbadconnections?NofalseautoReconnectForPoolsUseareconnectionstrategyappropriateforconnectionpools(defaultstofalse)NofalsefailOverReadOnlyWhenfailingoverinautoReconnectmode,shouldtheconnectionbesettoread-only?NotruemaxReconnectsMaximumnumberofreconnectstoattemptifautoReconnectistrue,defaultis3.No3initialTimeoutIfautoReconnectisenabled,theinitialtimetowaitbetweenre-connectattempts(inseconds,defaultsto2).No2queriesBeforeRetryMasterNumberofqueriestoissuebeforefallingbacktomasterwhenfailedover(whenusingmulti-hostfailover).Whicheverconditionismetfirst,queriesBeforeRetryMasterorsecondsBeforeRetryMasterwillcauseanattempttobemadetoreconnecttothemaster.Defaultsto50.No50secondsBeforeRetryMasterHowlongshouldthedriverwait,whenfailedover,beforeattemptingtoreconnecttothemasterserver?Whicheverconditionismetfirst,queriesBeforeRetryMasterorsecondsBeforeRetryMasterwillcauseanattempttobemadetoreconnecttothemaster.Timeinseconds,defaultsto30No30SecurityallowMultiQueriesAllowtheuseof;todelimitmultiplequeriesduringonestatement(true/false,defaultstofalseNofalseuseSSLUseSSLwhencommunicatingwiththeserver(true/false),defaultstofalseNofalserequireSSLRequireSSLconnectionifuseSSL=true?(defaultstofalse).NofalseallowUrlInLocalInfileShouldthedriverallowURLsinLOADDATALOCALINFILEstatements?NofalseparanoidTakemeasurestopreventexposuresensitiveinformationinerrormessagesandcleardatastructuresholdingsensitivedatawhenpossible?(defaultstofalse)NofalsePerformanceExtensionsmetadataCacheSizeThenumberofqueriestocacheResultSetMetadataforifcacheResultSetMetaDataissettotrue(default50)No50prepStmtCacheSizeIfpreparedstatementcachingisenabled,howmanypreparedstatementsshouldbecached?No25prepStmtCacheSqlLimitIfpreparedstatementcachingisenabled,whatsthelargestSQLthedriverwillcachetheparsingfor?No256cacheCallableStmtsShouldthedrivercachetheparsingstageofCallableStatementsNofalsecachePrepStmtsShouldthedrivercachetheparsingstageofPreparedStatements?NofalsecacheResultSetMetadataShouldthedrivercacheResultSetMetaDataforStatementsandPreparedStatements?(Req.JDK-1.4+,true/false,defaultfalse)NofalsecacheServerConfigurationShouldthedrivercachetheresultsofSHOWVARIABLESandSHOWCOLLATIONonaper-URLbasis?NofalsedontUnpackBinaryResultsShouldthedriverdelayunpackingresultsfromserver-sidepreparedstatementsuntilthevaluesareaskedfor?NofalsedynamicCalendarsShouldthedriverretrievethedefaultcalendarwhenrequired,orcacheitperconnection/session?NofalseelideSetAutoCommitsIfusingMySQL-4.1ornewer,shouldthedriveronlyissuesetautocommit=nquerieswhentheserversstatedoesntmatchtherequestedstatebyConnection.setAutoCommit(boolean)?NofalseuseFastIntParsingUseinternalString->Integerconversionroutinestoavoidexcessiveobjectcreation?NotrueuseNewIOShouldthedriverusethejava.nio.*interfacesfornetworkcommunication(true/false),defaultstofalseNofalseuseReadAheadInputUsenewer,optimizednon-blocking,bufferedinputstreamwhenreadingfromtheserver?NotrueDebuging/ProfilingloggerThenameofaclassthatimplementscom.mysql.jdbc.log.Logthatwillbeusedtologmessagesto.(defaultiscom.mysql.jdbc.log.StandardLogger,whichlogstoSTDERR)Nocom.mysql.jdbc.log.StandardLoggerprofileSQLTracequeriesandtheirexecution/fetchtimestotheconfiguredlogger(true/false)defaultstofalseNofalseprofileSqlDeprecated,useprofileSQLinstead.Tracequeriesandtheirexecution/fetchtimesonSTDERR(true/false)defaultstofalseNomaxQuerySizeToLogControlsthemaximumlength/sizeofaquerythatwillgetloggedwhenprofilingortracingNo2048packetDebugBufferSizeThemaximumnumberofpacketstoretainwhenenablePacketDebugistrueNo20slowQueryThresholdMillisIflogSlowQueriesisenabled,howlongshouldaquery(inms)beforeitisloggedasslow?No2000useUsageAdvisorShouldthedriverissueusagewarningsadvisingproperandefficientusageofJDBCandMySQLConnector/Jtothelog(true/false,defaultstofalse)?NofalsedumpQueriesOnExceptionShouldthedriverdumpthecontentsofthequerysenttotheserverinthemessageforSQLExceptions?NofalseenablePacketDebugWhenenabled,aring-bufferofpacketDebugBufferSizepacketswillbekept,anddumpedwhenexceptionsarethrowninkeyareasinthedriverscodeNofalseexplainSlowQueriesIflogSlowQueriesisenabled,shouldthedriverautomaticallyissueanEXPLAINontheserverandsendtheresultstotheconfiguredlogataWARNlevel?NofalselogSlowQueriesShouldqueriesthattakelongerthanslowQueryThresholdMillisbelogged?NofalsetraceProtocolShouldtrace-levelnetworkprotocolbelogged?NofalseMiscellaneoususeUnicodeShouldthedriveruseUnicodecharacterencodingswhenhandlingstrings?Shouldonlybeusedwhenthedrivercantdeterminethecharactersetmapping,oryouaretryingtoforcethedrivertouseacharactersetthatMySQLeitherdoesntnativelysupport(suchasUTF-8),true/false,defaultstotrueNofalsecharacterEncodingIfuseUnicodeissettotrue,whatcharacterencodingshouldthedriverusewhendealingwithstrings?(defaultsistoautodetect)NocharacterSetResultsCharactersettotelltheservertoreturnresultsas.NoconnectionCollationIfset,tellstheservertousethiscollationviasetconnection_collationNoallowNanAndInfShouldthedriverallowNaNor+/-INFvaluesinPreparedStatement.setDouble()?NofalseautoDeserializeShouldthedriverautomaticallydetectandde-serializeobjectsstoredinBLOBfields?NofalsecapitalizeTypeNamesCapitalizetypenamesinDatabaseMetaData?(usuallyonlyusefulwhenusingWebObjects,true/false,defaultstofalse)NofalseclobberStreamingResultsThiswillcauseastreamingResultSettobeautomaticallyclosed,andanyoustandingdatastillstreamingfromtheservertobediscardedifanotherqueryisexecutedbeforeallthedatahasbeenreadfromtheserver.NofalsecontinueBatchOnErrorShouldthedrivercontinueprocessingbatchcommandsifonestatementfails.TheJDBCspecallowseitherway(defaultstotrue).NotrueemulateLocatorsN/ANofalseignoreNonTxTablesIgnorenon-transactionaltablewarningforrollback?(defaultstofalse).NofalsejdbcCompliantTruncationShouldthedriverthrowjava.sql.DataTruncationexceptionswhendataistruncatedasisrequiredbytheJDBCspecificationwhenconnectedtoaserverthatsupportswarnings(MySQL4.1.0andnewer)?NotruemaxRowsThemaximumnumberofrowstoreturn(0,thedefaultmeansreturnallrows).No-1pedanticFollowtheJDBCspectotheletter.NofalserelaxAutoCommitIftheversionofMySQLthedriverconnectstodoesnotsupporttransactions,stillallowcallstocommit(),rollback()andsetAutoCommit()(true/false,defaultstofalse)?NofalserollbackOnPooledCloseShouldthedriverissuearollback()whenthelogicalconnectioninapoolisclosed?NotrueserverTimezoneOverridedetection/mappingoftimezone.UsedwhentimezonefromserverdoesntmaptoJavatimezoneNostrictFloatingPointUsedonlyinolderversionsofcompliancetestNofalsestrictUpdatesShouldthedriverdostrictchecking(allprimarykeysselected)ofupdatableresultsets(true,false,defaultstotrue)?NotruetinyInt1isBitShouldthedrivertreatthedatatypeTINYINT(1)astheBITtype(becausetheserversilentlyconvertsBIT->TINYINT(1)whencreatingtables)?NotrueultraDevHackCreatePreparedStatementsforprepareCall()whenrequired,becauseUltraDevisbrokenandissuesaprepareCall()for_all_statements?(true/false,defaultstofalse)NofalseuseHostsInPrivilegesAdd@hostnametousersinDatabaseMetaData.getColumn/TablePrivileges()(true/false),defaultstotrue.NotrueuseOldUTF8BehaviorUsetheUTF-8behaviorthedriverdidwhencommunicatingwith4.0andolderserversNofalseuseOnlyServerErrorMessagesDontprependstandardSQLStateerrormessagestoerrormessagesreturnedbytheserver.NotrueuseServerPrepStmtsUseserver-sidepreparedstatementsiftheserversupportsthem?(defaultstotrue).NotrueuseSqlStateCodesUseSQLStandardstatecodesinsteadoflegacyX/Open/SQLstatecodes(true/false),defaultistrueNotrueuseStreamLengthsInPrepStmtsHonorstreamlengthparameterinPreparedStatement/ResultSet.setXXXStream()methodcalls(true/false,defaultstotrue)?NotrueuseTimezoneConverttime/datetypesbetweenclientandservertimezones(true/false,defaultstofalse)?NofalseuseUnbufferedInputDontuseBufferedInputStreamforreadingdatafromtheserverNotruezeroDateTimeBehaviorWhatshouldhappenwhenthedriverencountersDATETIMEvaluesthatarecomposedentirelyofzeroes(usedbyMySQLtorepresentinvaliddates)?Validvaluesareexception,roundandconvertToNull.Noexception
Connector/JalsosupportsaccesstoMySQLvianamedpipesonWindowsNT/2000/XPusingtheNamedPipeSocketFactoryasaplugin-socketfactoryviathesocketFactoryproperty.IfyoudontuseanamedPipePathproperty,thedefaultof.pipeMySQLwillbeused.IfyouusetheNamedPipeSocketFactory,thehostnameandportnumbervaluesintheJDBCurlwillbeignored.
AddingthefollowingpropertytoyourURLwillenabletheNamedPipeSocketFactory:
socketFactory=com.mysql.jdbc.NamedPipeSocketFactory
NamedpipesonlyworkwhenconnectingtoaMySQLserveronthesamephysicalmachineastheonetheJDBCdriverisbeingusedon.Insimpleperformancetests,itappearsthatnamedpipeaccessisbetween30%-50%fasterthanthestandardTCP/IPaccess.
Youcancreateyourownsocketfactoriesbyfollowingtheexamplecodeincom.mysql.jdbc.NamedPipeSocketFactory,orcom.mysql.jdbc.StandardSocketFactory.
posted2005-01-0412:54:00.0
还得说上一点,就java本质而言,是面相对象的,但是你有没有发现,java也不全是,比如说基本类型,int,那他就是整型而不是对象,转换类型是还得借助包装类。 |
|