In the struts-config.xml, note that the <data-sources> element is located before <form-beans> and <action-mapping>.
---- Configure the Oracle Data Source ----------
<Datasources>
<Datasource key = "oracledb1"
Type = "org. Apache. commons. DBCP. basicdataource">
<Set-Property = "driverclassname"
Value = "oracle. JDBC. Driver. oracledriver"/>
<Set-Property = "url"
Value = "JDBC: oracle: thin@127.0.0.1: 1521: Database Sid"/>
<Set-Property = "maxactive"
Value = "5"/>
<Set-Property = "username"
Value = "system"/>
<Set-Property = "password"
Value = "okokokok"/>
<Set-Property = "autocommit"
Value = "true"/>
</Datasource>
</Datasources>
/*
Key: identifies the data source, which is stored in the servletcontext of actionservlet. It is used for future program code access to the data source.
Driverclassname: full Class Name of the database driver
URL: the URL to connect to the database
Maxactive: Maximum number of opened databases at the same time
Username: username used to connect to the database
Password: password used to connect to the database
Autocommit: sets whether to automatically submit an SQL statement after it is executed.
*/
---- Configure sqlserver data source ----------
<Data-source key = "sqlserdb1"
Type = "org. Apache. commons. DBCP. basicdatasource">
<Set-Property = "driverclassname"
Value = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"/>
<Set-Property = "url"
Value = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = test"/>
<Set-Property = "username"
Value = "sa"/>
<Set-Property = "password"
Value = "1234"/>
<Set-Property = "autocommit"
Value = "true"/>
</Data-source>
If org. Apache. commons. DBCP. basicdataource is abnormal when you restart tomcat after configuring the data source, go
Http://www.axint.net/apache/java-repository/commons-dbcp/jars/download the jarfile and put it in
In common under tomcat.
--------------------------------
Servletcontext context = servlet. getservletcontext ();
Datasource = (datasource) Context. getattribute ("oracledb1 ");