1. Overview
A recent Web project for a bank is on-line, deployed on their WebLogic machine, and, according to the bank's specifications, applications deployed on WebLogic server need to access the database, in principle, to manage database connections through the JDBC Connection pool provided by WebLogic.
In WebLogic server, create a database connection by configuring the JDBC data source. Database connections are established when a data source is directed or deployed to a server or cluster. Each data source contains a pooled set of database connections. The application finds the data source on the Jndi tree by name, gets a data source connection, completes the database operation, and calls Connection.close () to return the connection to the connection pool.
2. configuration steps explained
(1) Open the WebLogic Management Server, enter the WebLogic Management console , click on the left " services " → " data source ", then click on the right "new " → "a -like data source ".
(2) Fill in the "name", "Jndi name" of the JDBC data source, select the database type
Data Source Name: Is the WebLogic used to uniquely identify resource entries within the domain, not only does it require that multiple data sources configured within a domain not have duplicate names, and cannot be identical to other entities configured in the domain, such as hosts, clusters, and servers.
Jndi Name: Is the name used by the application to get the data source, as determined by the app.
(3) Select the driver for the Oracle database. In the type of drive, the Non-xa drive is generally better than the XA drive, and the 4th JDBC driver is used in non-special cases. As shown in the figure
(4) Transaction processing options, default.
(5) According to the information of the connected database, fill in the database connection information: the database to connect to, the IP address of the database, the port number to connect to the database, the user name and password used when logging into the database.
(6) Click "Test Configuration" button to test whether the data source is normal.
In this case, the following scenario appears:
Check the value of the URL, where the value is: Jdbc:oracle:thin:@10.0.2.55:1521:orcl.localdomain change to jdbc:oracle:thin:@10.0.2.55:1521/ Orcl.localdomain. Before the service name: Change to/.
Click the test configuration again, and the following appears, indicating that the data source was created successfully.
(7) Click Finish, go back to the data source interface, the target is empty, click the data Source link
(8) Click on the Target tab, select the server to which you want to deploy the data source, click Save, and the data source configuration is successful.
(9) Connection pool capacity configuration recommendations:
Select configuration→connection pooling to see the associated capacity configuration for the connection pool:
Initial capacity: Based on application needs configuration, for real-time trading class application system, generally set to meet daily operational demand peak requirements, while considering the database on the number of connections and capacity constraints
Maximum capacity: Set according to the application needs and the number of database connections
Minimum capacity: Normal and initial capacity are the same. 3. Getting and returning connections in the program
public class Dbutil {//Get log class private static final Logger log = Logger.getlogger ("Dbutil.class");
The factory class private static final String initial_context_factory = "Weblogic.jndi.WLInitialContextFactory" required to initialize the context;
WebLogic Server access address private static final String Provider_url = "t://10.0.2.181:8101";
The Jndi data source name in the WebLogic server is private static final String JNDI = "JNDI/SPLORCL";
private static context context = NULL;
static {hashtable<string, string> ht = new hashtable<string, string> ();
Ht.put (Context.initial_context_factory, initial_context_factory);
Ht.put (Context.provider_url, Provider_url);
try {//Initialize Jndi context information for WebLogic Server contextual = new InitialContext (HT);
} catch (Namingexception e) {log.info ("Dbutils:exit-->[context init error]");
Log.error ("InitialContext (naming)--[message:" + e.getmessage () + "]");
}} public static Connection GetConnect () {Context CTX = null;
Connection conn = null; try {ctx = Context
Gets the data source object Javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup (JNDI);
Get data source Connection conn = Ds.getconnection (); } catch (SQLException e) {log.info ("Dbutils:exit-->[getconnection error because:" + e.getmessage () + "]")
;
Log.error ("Get DB connection error (SQL)--[errorcode:" + e.geterrorcode () + "; Message:" + e.getmessage () + "]"); } catch (Namingexception e) {log.info ("Dbutils:exit-->[getconnection error because:" + e.getmessage () + "]
");
Log.error ("Get DB connection error (naming)--[message:" + e.getmessage () + "]");
} catch (Exception e) {log.info ("Dbutils:exit-->[getconnection error because:" + e.getmessage () + "]");
Log.error ("Get DB connection Error (Other)--[message:" + e.getmessage () + "]");
} return conn;
public static void Close (ResultSet RS, Statement Stat, Connection conn) {try {if (rs! = null) rs.close ();
if (stat! = null) stat.close (); IF (conn! = NULL) Conn.close ();
} catch (SQLException e) {log.info ("Dbutils:exit-->[close resource error because:" + e.getmessage () + "]");
Log.error ("Close DB connection Error--[errorcode:" + e.geterrorcode () + "; Message:" + e.getmessage () + "]");
}
}
}