MySql 连接字符串

xiaoxiao2022-12-06  185

 mysql JDBC 驱动常用的有两个,一个是gjt(Giant Java Tree)组织提供的mysql驱动,其JDBC Driver名称(JAVA类名)为:org.gjt.mm.mysql.Driver详情请参见网站:http://www.gjt.org/另一个是mysql官方提供的JDBC Driver,其JAVA类名为:com.mysql.jdbc.Driver驱动下载网址:http://dev.mysql.com/downloads/,进入其中的MySQL Connector/J区域下载。mysql JDBC URL格式如下:jdbc:mysql://[host:port]/[database][?参数名1][=参数值1][&参数名2][=参数值2]...

参数名称参数说明缺省值最低版本要求user数据库用户名(用于连接数据库)所有版本password用户密码(用于连接数据库)所有版本useUnicode是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为truefalse1.1gcharacterEncoding当useUnicode设置为true时,指定字符编码。比如可设置为gb2312或gbkfalse1.1gautoReconnect当数据库连接异常中断时,是否自动重新连接?false1.1autoReconnectForPools是否使用针对数据库连接池的重连策略false3.1.3failOverReadOnly自动重连成功后,连接是否设置为只读?true3.0.12maxReconnectsautoReconnect设置为true时,重试连接的次数31.1initialTimeoutautoReconnect设置为true时,两次重连之间的时间间隔,单位:秒21.1connectTimeout和数据库服务器建立socket连接时的超时,单位:毫秒。 0表示永不超时,适用于JDK 1.4及更高版本03.0.1socketTimeoutsocket操作(读写)超时,单位:毫秒。 0表示永不超时03.0.1

对应中文环境,通常mysql连接URL可以设置为:jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk&autoReconnect=true&failOverReadOnly=false在使用数据库连接池的情况下,最好设置如下两个参数:autoReconnect=true&failOverReadOnly=false需要注意的是,在xml配置文件中,url中的&符号需要转义。比如在tomcat的server.xml中配置数据库连接池时,mysql jdbc url样例如下:jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=gbk&autoReconnect=true&failOverReadOnly=false

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=569304

转载请注明原文地址: https://www.6miu.com/read-4979311.html

最新回复(0)