Create a JDBC Connection

Using DriverManager's getConnection Method:
First way is to use the DriverManger's getConnection() method. this is a most popular way to create a Connection from Database.Following are the code. This method except three parameter. url, username and password.



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


Using DriverManager's registerDriver method :
Second way to use registerDriver() method of DriverManager class. this method is static like first one and use a refrence of Driver class or its subclass. Following is the code for demonstrating the same.



DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email