ORACLE JDBC: DriverManager or OracleDataSource

When I tried to connect to my Oracle 11.1.0.7.0 database using jdbc with the corresponding version ojdbc6.jar , I found two options. Assuming DBURL form string

 jdbc:oracle:thin:@//#DBSERV#:#DBPORT#/#DBSID# 

where these hashed words ("...") are filled in correctly, they (options) look like

  • ods = new oracle.jdbc.pool.OracleDataSource ();
    ods.setPassword (Datenbankpasswort);
    ods.setUser (Datenbankuser);
    ods.setURL (DbUrl);
    DBConn = ods.getConnection;
  • java.sql.DriverManager.registerDriver (new oracle.jdbc.OracleDriver ());
    DBConn = java.sql.DriverManager.getConnection (DbUrl, Datenbankuser, Datenbankpasswort);

and then dbconn.getConnection(); .
So far I think both should work, but I wonder which way is better? Maybe one is out of date?
Further, I can only connect to option 1. Perhaps I missed something in option 2.
I am interested in any suggestions.

+4
source share
1 answer

DataSource is the preferred way to provide connectivity to the database. This kind of high-level object "does" the job for you and access to lower classes, such as DriverManager

You can find some more powerful versions of the DataSource where the connections are combined and can be reused: ConnectionPoolDataSource

DataSource usually configured and registered in the JNDI tree.
Typically, applications / web servers such as Tomcat offer the ability to configure (and share) a DataSource.

+2
source

All Articles