做微信h5的网站北京网站优化价格
news/
2025/9/22 23:34:48/
文章来源:
做微信h5的网站,北京网站优化价格,网站设计素材免费下载,企业信用信息公示系统河南java.sql.Driver接口规定了Driver应该具有以下功能#xff0c;重要的有三个acceptsURL判断jdbcUrl是否支持、创建一个连接、获取属性信息#xff0c;三个主要接口。
下边以 NonRegisteringDriver 类的源码简单分析以下。
acceptsURL
acceptsURL(String url) 方法用来测试…java.sql.Driver接口规定了Driver应该具有以下功能重要的有三个acceptsURL判断jdbcUrl是否支持、创建一个连接、获取属性信息三个主要接口。
下边以 NonRegisteringDriver 类的源码简单分析以下。
acceptsURL
acceptsURL(String url) 方法用来测试对指定的url该驱动能否打开这个url连接。driver对自己能够连接的url会制定自己的协议只有符合自己的协议形式的url才认为自己能够打开这个url如果能够打开返回true反之返回false
Mysql-JDBC支持的驱动协议有
jdbc:mysqlsrv:jdbc:mysqlsrv:loadbalance:jdbc:mysqlsrv:replication:mysqlxsrv:jdbc:mysql:jdbc:mysql:loadbalance:jdbc:mysql:replication:mysqlx:
connect
这里会根据URL 创建一个连接。一般是ConnectionImpl类型下一篇文章会细说一下。其他类型的连接就先不看了。
public java.sql.Connection connect(String url, Properties info) throws SQLException {try {// 如果url是不自持的连接协议则返回nullif (!ConnectionUrl.acceptsUrl(url)) {return null;}ConnectionUrl conStr ConnectionUrl.getConnectionUrlInstance(url, info);switch (conStr.getType()) {case SINGLE_CONNECTION:return com.mysql.cj.jdbc.ConnectionImpl.getInstance(conStr.getMainHost());case FAILOVER_CONNECTION:case FAILOVER_DNS_SRV_CONNECTION:return FailoverConnectionProxy.createProxyInstance(conStr);case LOADBALANCE_CONNECTION:case LOADBALANCE_DNS_SRV_CONNECTION:return LoadBalancedConnectionProxy.createProxyInstance(conStr);case REPLICATION_CONNECTION:case REPLICATION_DNS_SRV_CONNECTION:return ReplicationConnectionProxy.createProxyInstance(conStr);default:return null;}} catch (UnsupportedConnectionStringException e) {// when Connector/J cant handle this connection string the Driver must return nullreturn null;} catch (CJException ex) {throw ExceptionFactory.createException(UnableToConnectException.class,Messages.getString(NonRegisteringDriver.17, new Object[] { ex.toString() }), ex);}
}SINGLE_CONNECTION 会创建一个 ConnectionImpl public static JdbcConnection getInstance(HostInfo hostInfo) throws SQLException {return new ConnectionImpl(hostInfo);}getPropertyInfo
获取这些属性信息 HOST、PORT、DBNAME、USER、PASSWORD
Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {String host ;String port ;String database ;String user ;String password ;if (!isNullOrEmpty(url)) {ConnectionUrl connStr ConnectionUrl.getConnectionUrlInstance(url, info);if (connStr.getType() Type.SINGLE_CONNECTION) {HostInfo hostInfo connStr.getMainHost();info hostInfo.exposeAsProperties();}}if (info ! null) {host info.getProperty(PropertyKey.HOST.getKeyName());port info.getProperty(PropertyKey.PORT.getKeyName());database info.getProperty(PropertyKey.DBNAME.getKeyName());user info.getProperty(PropertyKey.USER.getKeyName());password info.getProperty(PropertyKey.PASSWORD.getKeyName());}DriverPropertyInfo hostProp new DriverPropertyInfo(PropertyKey.HOST.getKeyName(), host);hostProp.required true;hostProp.description Messages.getString(NonRegisteringDriver.3);DriverPropertyInfo portProp new DriverPropertyInfo(PropertyKey.PORT.getKeyName(), port);portProp.required false;portProp.description Messages.getString(NonRegisteringDriver.7);DriverPropertyInfo dbProp new DriverPropertyInfo(PropertyKey.DBNAME.getKeyName(), database);dbProp.required false;dbProp.description Messages.getString(NonRegisteringDriver.10);DriverPropertyInfo userProp new DriverPropertyInfo(PropertyKey.USER.getKeyName(), user);userProp.required true;userProp.description Messages.getString(NonRegisteringDriver.13);DriverPropertyInfo passwordProp new DriverPropertyInfo(PropertyKey.PASSWORD.getKeyName(), password);passwordProp.required true;passwordProp.description Messages.getString(NonRegisteringDriver.16);JdbcPropertySet propSet new JdbcPropertySetImpl();propSet.initializeProperties(info);ListDriverPropertyInfo driverPropInfo propSet.exposeAsDriverPropertyInfo();DriverPropertyInfo[] dpi new DriverPropertyInfo[5 driverPropInfo.size()];dpi[0] hostProp;dpi[1] portProp;dpi[2] dbProp;dpi[3] userProp;dpi[4] passwordProp;System.arraycopy(driverPropInfo.toArray(new DriverPropertyInfo[0]), 0, dpi, 5, driverPropInfo.size());return dpi;
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/910753.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!