![]() In the below DriverManager Example program, we have used getDriver, getLoginTimeout and setLoginTimeout methods. We can handle the exception either by using the Try-Catch block or by adding throws keyword with method Signature. The getConnection() method throws SQLException when there is an error that occurred during an interaction with the Database. If you set LoginTimeout as 0, then the driver will wait infinitely while establishing the connection with DB It is used to set the time (seconds) that a driver can wait till that time while establishing a connection to connect with DB. Public static void setLoginTimeout(int seconds) It returns the maximum time (seconds), a driver can wait while establishing the connection. If the driver is not found, it won’t take any action. It is used to remove the specified driver from the registered list of drivers. Public static void deregisterDriver(Driver driver) If the driver is already registered then it won’t take any action. It is used to register the driver to the DriverManager. Public static synchronized void registerDriver(Driver driver) It returns an enumeration that has all the registered drivers of the DriverManager. It returns the driver from the registered driver's list which understands the URL specified in the method. Public static Driver getDriver(String URL) It works like getConnection(String), but here URL, username, and password given as separate parameters. Public static Connection getConnection(String URL, String UserName, String Password) The String parameter has URL, username, and password to connect with DB. It attempts to establish the connection to the given Database and select an appropriate driver from the registered drivers. Public static Connection getConnection(String URL) It maintains the single instance of each registered driver.ĭriverManager class has the following methods: It tracks the details of the driver that are available and handles establishing the connection between the database and an appropriate driver. It acts as an interface between the user and the drivers. The main job of Driver Manager is to register and load the drivers and establish the connection. The main purpose of Driver Manager in JDBC is to provide the basic services to manage the set of drivers that are available to use in the application.Ĭoncurrently, multiple drivers can be accessed by the application you just need to mention the JDBC driver using URL. Object class is the parent class of all the classes in Java. PreparedStatement For ExecuteBatch Methodĭriver Manager Class is in the java.sql package and it extends Object class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |