Describe how to open a database connection using JDBC.
Opening a database connection:The database connection should be established after registering the drivers. The getConnection is used to open a database connection.
The following code snippet illustrates this: Connection con;
con = DriverManager.getConnection(url,"scott","tiger");// returns the connection object where url specifies the database server port, ip address,domain name etc.
For ex:
jdbc:oracle:thin:@192.137.63.230:1521:MyCompany
The ip address is an imaginary one and not intended to specify any specific system. The “scott” and “tiger” are the user name and passwords respectively.