MySQL中關(guān)于JDBC URL幾個重要參數(shù)說明
MySQL JDBC Driver
常用的有兩個,一個是gjt(Giant Java Tree)組織提供的mysql驅(qū)動,其JDBC Driver名稱(JAVA類名)為:org.gjt.mm.mysql.Driver
詳情請參見網(wǎng)站:http://www.gjt.org/
#t#另一個是MySQL官方提供的JDBC Driver,其JAVA類名為:com.mysql.jdbc.Driver
驅(qū)動下載網(wǎng)址:http://dev.mysql.com/downloads/,進(jìn)入其中的MySQL Connector/J區(qū)域下載。
MySQL JDBC URL格式如下:
jdbc:mysql://[host:port],[host:port].../[database][?參數(shù)名1][=參數(shù)值1][&參數(shù)名2][=參數(shù)值2]...
現(xiàn)只列舉幾個重要的MySQL JDBC URL參數(shù),如下表所示:
對應(yīng)中文環(huán)境,通常MySQL連接URL可以設(shè)置為:
- jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk&autoReconnect=true&failOverReadOnly=false
在使用數(shù)據(jù)庫連接池的情況下,***設(shè)置如下兩個參數(shù):
- autoReconnect=true&failOverReadOnly=false
需要注意的是,在xml配置文件中,url中的&符號需要轉(zhuǎn)義成&。比如在tomcat的server.xml中配置數(shù)據(jù)庫連接池時,mysql jdbc url樣例如下:
- jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk
- &autoReconnect=true&failOverReadOnly=false
【編輯推薦】