在加载jdbc:odbc驱动程序时,Class类中的forName()方法做了什么? [英] What does forName() method in the Class class do, when loading jdbc:odbc driver?
问题描述
我正在学习如何使我的Java应用程序与MS Access数据库通信。
I am learning to enable my Java application to communicate with a MS Access database.
我不确定一种方法,即Class.forName()方法。我传递的参数是sun.jdbc.odbc.JdbcOdbcDriver,它加载用于访问数据库的jdbc:odbc桥。
I am unsure of one method, the Class.forName() method. The parameter I pass is "sun.jdbc.odbc.JdbcOdbcDriver", which loads the jdbc:odbc bridge for accessing a database.
Class.forName()究竟做了什么,为什么需要它?
What does the Class.forName() do exactly and why is it needed?
非常感谢。
推荐答案
Class.forName()
使ClassLoader将类加载到内存中。 JDBC驱动程序类具有静态初始化程序,它们使用DriverManager注册它们以供进一步使用。使用 Class.forName()
后,使用 DriverManager.getConnection(jdbc:*,数据库,用户名,密码)
, jdbc:
已经加载到内存中。
Class.forName()
causes ClassLoader to load the class into memory. JDBC driver classes have static initializers that register them with DriverManager for further use. After you use Class.forName()
, and use DriverManager.getConnection("jdbc:*", database, username, password)
, the jdbc:
is already loaded in memory.
这篇关于在加载jdbc:odbc驱动程序时,Class类中的forName()方法做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!