Configuration of JSP data sources in struts Architecture

Source: Internet
Author: User

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 ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.