方法 | 描述 |
---|
1) public static synchronized void registerDriver(Driver driver) | 用于向 DriverManager 注册给定的驱动程序。如果给定的驱动程序已注册,则该方法不执行任何操作。 |
2) public static synchronized void deregisterDriver(Driver driver) | 用于向 DriverManager 取消注册给定的驱动程序(从列表中删除驱动程序)。如果给定的驱动程序已从列表中删除,则该方法不执行任何操作。 |
3) public static Connection getConnection(String url) throws SQLException | 用于建立与指定 url 的连接。当给定数据库的相应 Driver 类未向 DriverManager 注册时,将抛出 SQLException。 |
4) public static Connection getConnection(String url,String userName,String password) throws SQLException | 用于建立与指定 url、用户名和密码的连接。当给定数据库的相应 Driver 类未向 DriverManager 注册时,将抛出 SQLException。 |
5) public static Driver getDriver(String url) | 此方法返回理解所提到的 URL(在方法的参数中存在)的那些驱动程序,前提是这些驱动程序在注册驱动程序列表中。 |
6) public static int getLoginTimeout() | 此方法返回驱动程序被允许等待与数据库建立连接的时间长度。 |
7) public static void setLoginTimeout(int sec) | 该方法以秒为单位提供时间。参数中提到的 sec 是驱动程序被允许等待与数据库建立连接的最大时间。如果在此方法的参数中传递 0,则驱动程序在尝试与数据库建立连接时将无限期等待。 |
8) public static Connection getConnection(String URL, Properties prop) throws SQLException | 此方法在创建与指定 URL(此方法的第一个参数)处的数据库的连接后返回一个连接对象。第二个参数“prop”用于获取数据库的认证详细信息(用户名和密码)。与 getConnection() 方法的其他变体类似,当给定数据库的相应 Driver 类未向 DriverManager 注册时,此方法也会抛出 SQLException。 |