ProAnswers.org

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  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:@162.137.63.230:1221: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.