当前位置: 首页 > news >正文

申请免费网站公司互联网推广方式

申请免费网站公司,互联网推广方式,北京做百度网站,织梦模板自适应前言: java源码阅读,看看是怎么组织起来表达逻辑的,菜鸟笔记。 1.connection接口作数据库连接对象 1.1一阵土话 类a中有接口A作属性Field,接口A中定义了抽象方法aM,规定了返回值是接口B 调用:类a对象.…

前言:

java源码阅读,看看是怎么组织起来表达逻辑的,菜鸟笔记。

1.connection接口作数据库连接对象

1.1一阵土话

类a中有接口A作属性Field,接口A中定义了抽象方法aM,规定了返回值是接口B

调用:类a对象.接口A对象(接口实例化).aM(接口方法),返回值接口B的实现类对象(aM的返回值是对象)

1.2原java语句在这里:

        //获取数据库的连接对象Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db3","root","root");
 

1.3解读:DriverManager.getConnection ---DriverManager的静态方法getConnection

getConnection方法原型:

    public static Connection getConnection(String url,String user, String password) throws SQLException {java.util.Properties info = new java.util.Properties();if (user != null) {info.put("user", user);}if (password != null) {info.put("password", password);}return (getConnection(url, info, Reflection.getCallerClass()));}

查看return内容: return (getConnection(url, info, Reflection.getCallerClass()));

继续查看getConnection()方法
    private static Connection getConnection(String url, java.util.Properties info, Class<?> caller) throws SQLException {/** When callerCl is null, we should check the application's* (which is invoking this class indirectly)* classloader, so that the JDBC driver class outside rt.jar* can be loaded from here.*/ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;synchronized(DriverManager.class) {// synchronize loading of the correct classloader.if (callerCL == null) {callerCL = Thread.currentThread().getContextClassLoader();}}if(url == null) {throw new SQLException("The url cannot be null", "08001");}println("DriverManager.getConnection(\"" + url + "\")");// Walk through the loaded registeredDrivers attempting to make a connection.// Remember the first exception that gets raised so we can reraise it.SQLException reason = null;for(DriverInfo aDriver : registeredDrivers) {// If the caller does not have permission to load the driver then// skip it.if(isDriverAllowed(aDriver.driver, callerCL)) {try {println("    trying " + aDriver.driver.getClass().getName());Connection con = aDriver.driver.connect(url, info);if (con != null) {// Success!println("getConnection returning " + aDriver.driver.getClass().getName());return (con);}} catch (SQLException ex) {if (reason == null) {reason = ex;}}} else {println("    skipping: " + aDriver.getClass().getName());}}// if we got here nobody could connect.if (reason != null)    {println("getConnection failed: " + reason);throw reason;}println("getConnection: no suitable driver found for "+ url);throw new SQLException("No suitable driver found for "+ url, "08001");}

找到返回值项return(con);

       for(DriverInfo aDriver : registeredDrivers) {// If the caller does not have permission to load the driver then// skip it.if(isDriverAllowed(aDriver.driver, callerCL)) {try {println("    trying " + aDriver.driver.getClass().getName());Connection con = aDriver.driver.connect(url, info);if (con != null) {// Success!println("getConnection returning " + aDriver.driver.getClass().getName());return (con);}} catch (SQLException ex) {if (reason == null) {reason = ex;}}} else {println("    skipping: " + aDriver.getClass().getName());}}

其中

 Connection con = aDriver.driver.connect(url, info);

就是需要的结果,而这一段可以衔接上1.1,分析如下:

DriverInfo类,包含了接口Drive

class DriverInfo {final Driver driver;DriverAction da;DriverInfo(Driver driver, DriverAction action) {this.driver = driver;da = action;}

 接口里有抽象方法connect,返回值是接口对象connection

public interface Driver {Connection connect(String url, java.util.Properties info)throws SQLException;

aDriver是DriverInfo对象,driver是Driver接口类型的属性,connect是Driver接口方法

  for(DriverInfo aDriver : registeredDrivers) {// If the caller does not have permission to load the driver then// skip it.if(isDriverAllowed(aDriver.driver, callerCL)) {try {println("    trying " + aDriver.driver.getClass().getName());Connection con = aDriver.driver.connect(url, info);if (con != null) {// Success!println("getConnection returning " + aDriver.driver.getClass().getName());return (con);}

如此可以返回一个Connection接口的实现类对象

小结:java里常用接口来实现目的,而不一定在意其具体实现类是什么。

            Java里数据传递基本是以对象进行的。

http://www.lbrq.cn/news/2550493.html

相关文章:

  • 网站关键词优化怎么做it学校培训学校哪个好
  • 做网站 要学 什么语言爱站网站长工具
  • 做网站的市场前景网络互联网推广
  • 镇江个人网站建设2345系统导航
  • 网站域名一年多少钱镇江网站建设方案
  • 北京黑马培训机构怎么样网站优化排名易下拉系统
  • cms 做网站模板seo l
  • 安徽网站开发培训价格淘宝如何刷关键词增加权重
  • 网站导航为什么用ul列表做关键词排名点击软件
  • c做网站教程baidu百度首页官网
  • 做视频网站的挣钱吗萧山seo
  • 自适应 WordPress 主题seo快速排名软件平台
  • 网站没有流量个人引流推广怎么做
  • wordpress生成静态 mip网站做优化好还是推广好
  • 双鸭山网站建设企业郑州今天刚刚发生的新闻
  • 网站建设流程步骤上海网站快速优化排名
  • wordpress在百度排名靠前seo经验是什么
  • 北京企业网站搭建油烟机seo关键词
  • 天津市建设 中标公示网站东莞疫情最新通知
  • 网站建设设计技术方案模板下载如何推销产品给客户
  • 织梦美女图片网站模板站长工具永久
  • 制作企业网站页面多少钱seo是指
  • 提供购物网站建设新闻发布最新新闻
  • 做网站就是做服务成都百度推广电话号码是多少
  • 奢侈品网站设计沈阳seo网站关键词优化
  • 钦州网站建设广东企业网站seo哪里好
  • 关于做公司网站网络推广项目外包公司
  • 网站被恶意关键字访问重庆seo网络推广关键词
  • 股票专业网站seo电商运营是什么意思
  • wordpress主题 破解主题下载地址seo查询工具网站
  • 解决 InputStream 只能读取一次问题
  • 力扣热题100---------206.反转链表
  • 函数 dirfd 详解
  • 从入仓到结算全自动化:易境通如何重构散货拼柜业务流程?
  • 每日练习(红黑树)
  • 前端框架Vue3(二)——Vue3核心语法之OptionsAPI与CompositionAPI与setup