Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

configuring datasource in struts-config.xml

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am learning Struts and I want how to configure the data source in struts-config.xml. i.e., connection to a database. it can be either oracle / sql server. I am trying to add the username and password in the DB. (all the action, actionforms are ready). pls tell / sample site for configuring db in struts-config.xml
 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the reply that I got here in regard to database access - should prove useful to you.
http://www.coderanch.com/t/54917/Struts/Database-connection-method
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

struts-config.xml
=================

<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource" key="userDB">
<set-property property="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<set-property property="url" value="jdbc racle:thin:@112.118.5.28:1521 rcl" />
<set-property property="username" value="seet" />
<set-property property="password" value="seet" />
<set-property property="maxActive" value="10" />
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />
<set-property property="validationQuery" value="SELECT COUNT(*) FROM emp" />
</data-source>
</data-sources>

Ensure that all jar files related to Oracle and the dbcp datasource are present in the lib folder so that the build.xml has the following entries.

<path id="compile.classpath">
<pathelement path ="lib/struts-legacy.jar"/>
<pathelement path ="lib/commons-dbcp-1.2.1.jar"/>
<pathelement path ="lib/commons-pool-1.3.jar"/>
<pathelement path ="lib/classes12.jar"/>
<pathelement path ="lib/ojdbc14.jar"/>
......
</path>

Rgds,

Seetesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic