Spring及Spring boot java程序访问数据库 JDBC DriverManager

java的包下,驱动程序管理器类DriverManager负责管理驱动程序,Java访问数据的过程就是通过实现了JDBC规范的驱动实现类来访问数据的过程,java通过DriverManager来与不同数据库的驱动交互帮助它们实现数据正常访问过程(我们一直在做的建立连接,执行方法)
在这里插入图片描述

registerDriver 注册Driver

在这里插入图片描述

public static synchronized void registerDriver(java.sql.Driver driver,DriverAction da)

这个过程实际上就是将我们的Driver对象作为入参然后转化为一个修饰类 DriverInfo,然后放入DriverManager的已注册Driver的List数据结构保存。

在这里插入图片描述
在这里插入图片描述

Connection连接

getConnection(String url, String user, String password) 建立连接
   /**
     * Attempts to establish a connection to the given database URL.
     * The <code>DriverManager</code> attempts to select an appropriate driver from
     * the set of registered JDBC drivers.
     *<p>
     * <B>Note:</B> If the {@code user} or {@code password} property are
     * also specified as part of the {@code url}, it is
     * implementation-defined as to which value will take precedence.
     * For maximum portability, an application should only specify a
     * property once.
     *
     * @param url a database url of the form
     * <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
     * @param user the database user on whose behalf the connection is being
     *   made
     * @param password the user's password
     * @return a connection to the URL
     * @exception SQLException if a database access error occurs or the url is
     * {@code null}
     * @throws SQLTimeoutException  when the driver has determined that the
     * timeout value specified by the {@code setLoginTimeout} method
     * has been exceeded and has at least tried to cancel the
     * current database connection attempt
     */
    @CallerSensitive
    public static Connection getConnection(String url,
        String user, String password) throws SQLException {
   
        java.util.Properties info = new java.util.Properties(
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值