Connecting to database from JAVA using JDBC??



one from DATASoURCE
second from DriverManager.getConnection

program using a DataSource and a PooledConnection is:
import javax.naming.*;
import javax.sql.*;

...

Context context = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(
"jdbc/DataSource" );
Connection con = ds.getConnection(
"userID", "password" );

...

finally
{
if( con != null ) { con.close(); }
}

CONNECTION POOLING
a connection pool class overrides the close() method and marks the Connection as available. That's why it is important to ensure that close() is invoked. Otherwise, the pool considers the Connection to be in use and creates a new Connection the next time one is requested, losing the benefit of pooling.

Showing Answers 1 - 1 of 1 Answers

nirmala

  • Mar 20th, 2006
 

import java.sql.*;

public class JDBC

 {
    connection con = DriverManager.getConnection("jdbc:odbc:url","scott","tiger");

    }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions