aspose file tools*
The moose likes Struts and the fly likes more than one data-source in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "more than one data-source in Struts" Watch "more than one data-source in Struts" New topic
Author

more than one data-source in Struts

Abebe Belew
Greenhorn

Joined: Jul 21, 2004
Posts: 19
Hi,
I want to have connection to two different databases in struts.
in my struts-config.xml file I set up two <data-sources> as

<data-sources>
<data-source>
<set-property property="key" value="mysql"/>
<set-property property="autoCommit" value="true" />
<set-property property="description" value="MySql Datasource" />
<set-property property="driverClass" value="com.mysql.jdbc.Driver" />
<set-property property="maxCount" value="5" />
<set-property property="minCount" value="2" />
<set-property property="user" value="user" />
<set-property property="password" value="pass" />
<set-property property="url" value="jdbc:mysql://url ort/db_name" />
</data-source>

<data-source>
<set-property property="key" value="tiger"/>
<set-property property="autoCommit" value="true" />
<set-property property="description" value="java Datasource" />
<set-property property="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<set-property property="maxCount" value="5" />
<set-property property="minCount" value="2" />
<set-property property="user" value="usr" />
<set-property property="password" value="pass" />
<set-property property="url" value=
jdbc racle:thin:@url ort b_name" />
</data-source>

</data-sources>

I tried to access both connections in my Action as

javax.sql.DataSource dataSource_udb;
java.sql.Connection conn_tiger;
javax.sql.DataSource dataSource_mysql;
java.sql.Connection conn_mysql;

dataSource_udb = getDataSource(request, "tiger");
conn_tiger = dataSource_udb.getConnection();

dataSource_mysql = getDataSource(request);
conn_mysql = dataSource_mysql.getConnection();

but then i get an error message "Servlet action is currently unavailable" and in the log file
javax.servlet.UnavailableException: Initializing application data source org.apache.struts.action.DATA_SOURCE
I have been stuck with this for more than a week now. can anybody help me with this.
thanks so much.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

I think this would more approriate in the Struts forum, so moving it there.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: more than one data-source in Struts
 
Similar Threads
How can I get the "pageContext" object in jsp page?
Problem defining an Oracle datasource in struts-config.xml
value of DATA_SOURCE_KEY field in Action class
accesing database???
Prob using DataSource