jdbc DriverManager.getConnection("connection_url","username","password"); [英] jdbc DriverManager.getConnection("connection_url", "username", "password");

查看:162
本文介绍了jdbc DriverManager.getConnection("connection_url","username","password");的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我这里发生了什么事

Can anyone tell me wats happening here

Connection con =DriverManager.getConnection("connection_url", "username", "password");

连接接口和driverManager类如何关联? 我的意思是con是一个连接接口引用,它可以指向实现连接接口的类的对象或与连接接口有关的对象/实例....."DriverManager.getConnection"将返回什么以及如何返回由连接引用引用?

How connection interface and driverManager class are related ? I mean con is a connection interface reference which can point to an object of a class which implements connection interface or an object/instance which is related to connection interface .....what "DriverManager.getConnection" is returning and how it can be referred by a connection reference ??

我知道基本的答案,但它通过检查驱动程序的url返回连接,但是实际发生了什么呢?

I know the basic answer dat it returns a connection by checking the url of the driver but what is actually happening in detail ?

我是Java初学者,请帮助

I am a beginner java student please help

推荐答案

DriverManager跟踪已在JVM中加载的所有JDBC Driver(Driver有几种方法可以加载).

The DriverManager keeps track of all JDBC Drivers that have been loaded in your JVM (there are a couple of ways in which a Driver can be loaded).

当您要求DriverManager为您打开连接时,它会询问每个已加载的驱动程序是否可以处理您指定的URL.
如果Driver可以处理URL,则要求使用提供的用户名和密码连接到数据库. Driver提供一个实现Connection接口的连接对象.

When you ask the DriverManager to open a connection for you, it asks each of the loaded drivers whether it can handle the URL that you've specified.
If the Driver can handle the URL, then it is asked to connect to the database using the supplied username and password. The Driver supplies a connection object that implements the Connection interface.

DriverManager实际上只是一个小类,它知道每个已加载的Driver并处理正确的选择. Connection(和Statement等)的实现全部由Driver处理.

The DriverManager really is just a small class that knows about each loaded Driver and handles picking the right one. The implementation of Connection (and Statement, etc) is all handled by the Driver.

这篇关于jdbc DriverManager.getConnection("connection_url","username","password");的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆