You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eugene Volynskiy <ev...@imsi.com> on 2003/03/21 15:32:39 UTC

data-source problem

Hi,

I have a problem with data-source usage in Struts 1.1
When we had data-source defined in struts-config.xml without "key" attribute
is working just fine:
<data-sources>
 	 <data-source>       
		 <set-property property="driverClass"
value="com.sybase.jdbc2.jdbc.SybDriver" />       
		 <set-property property="url"
value="jdbc:sybase:Tds:server:port/db" />
		 <set-property property="maxCount" value="10" />
		 <set-property property="minCount" value="1" />
		 <set-property property="user" value="user" />
		 <set-property property="password" value="pass" />
	 </data-source>
</data-sources>
In this case I established connection to default data-source using
Action.DATA_SOURCE_KEY: 
 	      ServletContext context = servlet.getServletContext();
		DataSource dataSource = (DataSource)
context.getAttribute(Action.DATA_SOURCE_KEY);
	      Connection conn = dataSource.getConnection();
But as soon as I add key attribute to datasource:
   	 <data-source key="ds1">       
	 ...
       </data-source> 
and trying to getAttribute by key:
		...
		DataSource dataSource = (DataSource)
context.getAttribute("ds1");
		...
I have NullPointer Exception on any DB call I have.
I would appreciate any advise/suggestion on this.

Thank you,

Eugene 




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


Re: data-source problem

Posted by Stephen Smithstone <sk...@lchost.co.uk>.
Are u using an Action if so try

getDatasource( httpServletRequest , "ds1" );

as the Action has a method for getting a datasource  

On Friday 21 March 2003 2:32 pm, Eugene Volynskiy wrote:
> Hi,
>
> I have a problem with data-source usage in Struts 1.1
> When we had data-source defined in struts-config.xml without "key"
> attribute is working just fine:
> <data-sources>
>  	 <data-source>
> 		 <set-property property="driverClass"
> value="com.sybase.jdbc2.jdbc.SybDriver" />
> 		 <set-property property="url"
> value="jdbc:sybase:Tds:server:port/db" />
> 		 <set-property property="maxCount" value="10" />
> 		 <set-property property="minCount" value="1" />
> 		 <set-property property="user" value="user" />
> 		 <set-property property="password" value="pass" />
> 	 </data-source>
> </data-sources>
> In this case I established connection to default data-source using
> Action.DATA_SOURCE_KEY:
>  	      ServletContext context = servlet.getServletContext();
> 		DataSource dataSource = (DataSource)
> context.getAttribute(Action.DATA_SOURCE_KEY);
> 	      Connection conn = dataSource.getConnection();
> But as soon as I add key attribute to datasource:
>    	 <data-source key="ds1">
> 	 ...
>        </data-source>
> and trying to getAttribute by key:
> 		...
> 		DataSource dataSource = (DataSource)
> context.getAttribute("ds1");
> 		...
> I have NullPointer Exception on any DB call I have.
> I would appreciate any advise/suggestion on this.
>
> Thank you,
>
> Eugene
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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