You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Janice <ja...@shaw.ca> on 2004/03/16 20:56:54 UTC

urgent - data-source and container managed datasource

Hi There,

I'm getting ready to ship off my application and I'm trying to use the
application server (standalone oc4j) to hold the data source information
instead of having it in struts-config.xml.  Is this possible?

When jDeveloper deploys to the server it builds me a data-sources.xml file
which I presume is correct.  When I test the connection, its fine.

In web.xml I entered:

  <resource-ref>
    <res-ref-name>jdbc/bartCoreDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

Where "jdbc/bartCoreDS" matches the "location" entry of the data-source in
data-sources.xml.

Then I took out the data-sources from struts-config.xml.  I'm not terribly
surprised that now my application can't find the database.  The problem is I
don't know where to look for instructions on how to do this or if its even
possible.  Is there a way to put a data-source configuration in
struts-config.xml that tells it to look at the container, so that the
username and password aren't in it??

If I can provide more information, I will.  Time is running a bit short, so
I'd really, really appreciate a quick response.

Janice


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: urgent - data-source and container managed datasource

Posted by Richard Yee <ry...@yahoo.com>.
Janice,
Check out these links:
http://otn.oracle.com/sample_code/tech/java/codesnippet/j2ee/jdbc/JDBC_in_J2EE.html
http://otn.oracle.com/products/jdev/tips/duff/mysql_and_oc4j3.html

It works fine for me.

-Richard


--- Janice <ja...@shaw.ca> wrote:
> Hi There,
> 
> I'm getting ready to ship off my application and I'm
> trying to use the
> application server (standalone oc4j) to hold the
> data source information
> instead of having it in struts-config.xml.  Is this
> possible?
> 
> When jDeveloper deploys to the server it builds me a
> data-sources.xml file
> which I presume is correct.  When I test the
> connection, its fine.
> 
> In web.xml I entered:
> 
>   <resource-ref>
>     <res-ref-name>jdbc/bartCoreDS</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
>   </resource-ref>
> 
> Where "jdbc/bartCoreDS" matches the "location" entry
> of the data-source in
> data-sources.xml.
> 
> Then I took out the data-sources from
> struts-config.xml.  I'm not terribly
> surprised that now my application can't find the
> database.  The problem is I
> don't know where to look for instructions on how to
> do this or if its even
> possible.  Is there a way to put a data-source
> configuration in
> struts-config.xml that tells it to look at the
> container, so that the
> username and password aren't in it??
> 
> If I can provide more information, I will.  Time is
> running a bit short, so
> I'd really, really appreciate a quick response.
> 
> Janice
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Is there a way to have more than one controller servlets?

Posted by Amit Deokar <av...@email.arizona.edu>.
Is there a way to have more than one controller servlets in Struts. My aim
is to have a "main" controller manager several other controllers. Any
suggestions or help?

Thanks in advance.
-amit


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: urgent - data-source and container managed datasource

Posted by Shyam A <st...@yahoo.com>.
Hello,

I have configured my data source on OC4J standalone
version. Given below are snippets from the relevant
files:

In my data-sources.xml , I have
	<data-source	
class="com.evermind.sql.DriverManagerDataSource"
		name="TestDS"
		location="jdbc/OracleCoreDS"
		xa-location="jdbc/xa/OracleXADS"
		ejb-location="jdbc/TestDS"
		connection-driver="oracle.jdbc.driver.OracleDriver"
		url="jdbc:oracle:thin:@servername:1521:test"
		username="username"
		password="password"
		min-connections="5" 
		max-connections="20"		
		inactivity-timeout="30"
	/>

I "lookup" this data source in a DatabaseServlet,
which is loaded on server startup, and intialize a
static variable in my "DBConnection" class, which
manages database connections.

I use the code below:
<snip>
		InitialContext ic = new InitialContext();
		DataSource ds =
(DataSource)ic.lookup("jdbc/TestDS");
..............
DBConnection.dataSource=ds;		//initializeDataSource in
the DBConnection class
               
<snip>

In my DBConnection class, I have methods like
openConnection(), closeConnection() et al to handle
connections from the data source.

<snip>
public Connection openConnection() 
   {
    Connection con=null;
	try
	   {		
	   con = dataSource.getConnection();	
	   } 	   
	 catch(Exception e)
        {		  
          System.out.println("Error: Unable to get
connection " + e.getMessage());
		  	
        }
	return con;		  
   }	
<snip>

In order to load the DatabaseServlet on starup, I have
the following in the web.xml file:

<servlet>
    <servlet-name>database</servlet-name>
   
<servlet-class>obs.application.DatabaseServlet</servlet-class>
   
    <load-on-startup>1</load-on-startup>
  </servlet>


HTH,
Shyam


--- Janice <ja...@shaw.ca> wrote:
> Hi There,
> 
> I'm getting ready to ship off my application and I'm
> trying to use the
> application server (standalone oc4j) to hold the
> data source information
> instead of having it in struts-config.xml.  Is this
> possible?
> 
> When jDeveloper deploys to the server it builds me a
> data-sources.xml file
> which I presume is correct.  When I test the
> connection, its fine.
> 
> In web.xml I entered:
> 
>   <resource-ref>
>     <res-ref-name>jdbc/bartCoreDS</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
>   </resource-ref>
> 
> Where "jdbc/bartCoreDS" matches the "location" entry
> of the data-source in
> data-sources.xml.
> 
> Then I took out the data-sources from
> struts-config.xml.  I'm not terribly
> surprised that now my application can't find the
> database.  The problem is I
> don't know where to look for instructions on how to
> do this or if its even
> possible.  Is there a way to put a data-source
> configuration in
> struts-config.xml that tells it to look at the
> container, so that the
> username and password aren't in it??
> 
> If I can provide more information, I will.  Time is
> running a bit short, so
> I'd really, really appreciate a quick response.
> 
> Janice
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org