You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Amit Gupta <am...@computerware.co.in> on 2004/12/18 08:40:11 UTC

I want to use data source defined in stuts-config.xml in my bean. How can I do it ?

Hi dear,

 

I am struts newbie. I want to use data source defined in stuts-config.xml in my bean. How can I do it ?

 

Please help.

 

Amit Gupta   


Re: JNDI with tiles controller

Posted by Jim Douglas <jd...@hotmail.com>.
I appreciate your response.  DAO with JDNI retrieving data from a through a 
tiles controller ended up working and for those who may go down this path 
setting up a context on Tomcat 5.5.4 is very different so beware.

Jim


>From: Eddie Bush <ea...@gmail.com>
>Reply-To: Eddie Bush <ea...@gmail.com>
>To: Struts Users Mailing List <us...@struts.apache.org>
>Subject: Re: JNDI with tiles controller
>Date: Mon, 20 Dec 2004 19:28:04 -0600
>
>Jim,
>
>JNDI is the best-practice approach to dealing with acquisition of
>data-sources.  It's not always practical to use (for example, if you
>don't have control over the server config) but it sure is slick.
>
>Not knowing what is in the tile that produces the error, it's
>difficult to say what your error could be.  If you believe this to be
>a Tomcat configuration issue, you'd likely be better off asking it to
>the tomcat-user list.  Yes, there are people here that use Tomcat, but
>this is the Struts list and not everyone here uses Tomcat.
>
>If you're attempting to do your queries in your JSPs, I'd recommend
>against it.  Let your actions / business objects / DAOs deal with
>that.  Handling your queries in your JSPs is NOT a best practice
>approach.  An approach that tends to work for me is to write a set of
>DAOs or use an O/R mapper (http://db.apache.org/ojb/ is one).  The DAO
>appoach is really simple, but fairly powerful - it should suffice for
>most simple to moderately complex systems.
>
>There's a ton of best practice stuff in the Struts' site Resources
>section and User Guides.  There are Tomcat-specific configuration
>guides on the Tomcat site -- JNDI Howtos and, in fact, even DataSource
>Howtos.  It's really best to go to horse and get things from his
>mouth.
>
>Good Luck!
>
>Eddie
>
>On Mon, 20 Dec 2004 18:54:32 +0000, Jim Douglas <jd...@hotmail.com> wrote:
> > My first question is a design one.  Is JDNI the best way to access a
> > database from a Tiles controller?  If so, this is the JDNI class problem 
>I
> > have.
> >
> > This is the tomcat/conf/catalina/localhost/myapp.xml file,
> >
> > <Context path="/Myapp" docBase="Myapp" debug="5" reloadable="true"
> > crossContext="true">
> >        <Resource name="jdbc/UserDB" auth="Container" 
>type="javax.sql.DataSource"
> > />
> >        <ResourceParams name="jdbc/UserDB">
> >                <parameter>
> >                        <name>username</name>
> >                        <value>SYSDBA</value>
> >                </parameter>
> >                <parameter>
> >                        <name>password</name>
> >                        <value>password</value>
> >                </parameter>
> >                <parameter>
> >                        <name>driverClassName</name>
> >                        <value>interbase.interclient.Driver</value>
> >                </parameter>
> >                <parameter>
> >                        <name>url</name>                        
><value>jdbc:interbase://localhost//usr/opt/tomcat/webapps/database/main.gdb</value>
> >                </parameter>
> >        </ResourceParams>
> > </Context>
> >
> > This is my Myapp/WEB-INF/web.xml entry,
> >
> > <resource-ref>
> >   <description>DS Connection</description>
> >      <res-ref-name>jdbc/UserDB</res-ref-name>
> >      <res-type>javax.sql.DataSource</res-type>
> >      <res-auth>Container</res-auth>
> > </resource-ref>
> >
> > ...and this is the error,
> >
> > ERROR - ServletException in '/layouts/classicLayout.jsp': Cannot create 
>JDBC
> > driver of class '' for connect URL 'null'
> > javax.servlet.ServletException: Cannot create JDBC driver of class '' 
>for
> > connect URL 'null'
> >        at
> > 
>org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:880)
> >        at 
>org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
> >
> > For whatever reason it doens't seem to be loading the driver class.  
>This is
> > the line causing the error,
> >
> >                Connection conn = ds.getConnection();
> >
> > I'm using Tomcat 5.5.4(if JDNI is not the best way to acces a database 
>from
> > a Tiles Controller, what is, what is?)
> >
> >  (I can query by other means using the JDBC driver which is located in
> > ...tomcat/common/lib/, so it's JDNI that giving me the problem.)
> >
> > Thanks,
> > Jim,
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
>--
>Eddie Bush
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>



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


Re: JNDI with tiles controller

Posted by Eddie Bush <ea...@gmail.com>.
Jim,

JNDI is the best-practice approach to dealing with acquisition of
data-sources.  It's not always practical to use (for example, if you
don't have control over the server config) but it sure is slick.

Not knowing what is in the tile that produces the error, it's
difficult to say what your error could be.  If you believe this to be
a Tomcat configuration issue, you'd likely be better off asking it to
the tomcat-user list.  Yes, there are people here that use Tomcat, but
this is the Struts list and not everyone here uses Tomcat.

If you're attempting to do your queries in your JSPs, I'd recommend
against it.  Let your actions / business objects / DAOs deal with
that.  Handling your queries in your JSPs is NOT a best practice
approach.  An approach that tends to work for me is to write a set of
DAOs or use an O/R mapper (http://db.apache.org/ojb/ is one).  The DAO
appoach is really simple, but fairly powerful - it should suffice for
most simple to moderately complex systems.

There's a ton of best practice stuff in the Struts' site Resources
section and User Guides.  There are Tomcat-specific configuration
guides on the Tomcat site -- JNDI Howtos and, in fact, even DataSource
Howtos.  It's really best to go to horse and get things from his
mouth.

Good Luck!

Eddie

On Mon, 20 Dec 2004 18:54:32 +0000, Jim Douglas <jd...@hotmail.com> wrote:
> My first question is a design one.  Is JDNI the best way to access a
> database from a Tiles controller?  If so, this is the JDNI class problem I
> have.
> 
> This is the tomcat/conf/catalina/localhost/myapp.xml file,
> 
> <Context path="/Myapp" docBase="Myapp" debug="5" reloadable="true"
> crossContext="true">
>        <Resource name="jdbc/UserDB" auth="Container" type="javax.sql.DataSource"
> />
>        <ResourceParams name="jdbc/UserDB">
>                <parameter>
>                        <name>username</name>
>                        <value>SYSDBA</value>
>                </parameter>
>                <parameter>
>                        <name>password</name>
>                        <value>password</value>
>                </parameter>
>                <parameter>
>                        <name>driverClassName</name>
>                        <value>interbase.interclient.Driver</value>
>                </parameter>
>                <parameter>
>                        <name>url</name>                        <value>jdbc:interbase://localhost//usr/opt/tomcat/webapps/database/main.gdb</value>
>                </parameter>
>        </ResourceParams>
> </Context>
> 
> This is my Myapp/WEB-INF/web.xml entry,
> 
> <resource-ref>
>   <description>DS Connection</description>
>      <res-ref-name>jdbc/UserDB</res-ref-name>
>      <res-type>javax.sql.DataSource</res-type>
>      <res-auth>Container</res-auth>
> </resource-ref>
> 
> ...and this is the error,
> 
> ERROR - ServletException in '/layouts/classicLayout.jsp': Cannot create JDBC
> driver of class '' for connect URL 'null'
> javax.servlet.ServletException: Cannot create JDBC driver of class '' for
> connect URL 'null'
>        at
> org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:880)
>        at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
> 
> For whatever reason it doens't seem to be loading the driver class.  This is
> the line causing the error,
> 
>                Connection conn = ds.getConnection();
> 
> I'm using Tomcat 5.5.4(if JDNI is not the best way to acces a database from
> a Tiles Controller, what is, what is?)
> 
>  (I can query by other means using the JDBC driver which is located in
> ...tomcat/common/lib/, so it's JDNI that giving me the problem.)
> 
> Thanks,
> Jim,
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
Eddie Bush

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


JNDI with tiles controller

Posted by Jim Douglas <jd...@hotmail.com>.
My first question is a design one.  Is JDNI the best way to access a 
database from a Tiles controller?  If so, this is the JDNI class problem I 
have.

This is the tomcat/conf/catalina/localhost/myapp.xml file,

<Context path="/Myapp" docBase="Myapp" debug="5" reloadable="true" 
crossContext="true">
	<Resource name="jdbc/UserDB" auth="Container" type="javax.sql.DataSource" 
/>
	<ResourceParams name="jdbc/UserDB">
		<parameter>
			<name>username</name>
			<value>SYSDBA</value>
		</parameter>
		<parameter>
			<name>password</name>
			<value>password</value>
		</parameter>
		<parameter>
			<name>driverClassName</name>
			<value>interbase.interclient.Driver</value>
		</parameter>
		<parameter>
			<name>url</name>			<value>jdbc:interbase://localhost//usr/opt/tomcat/webapps/database/main.gdb</value>
		</parameter>
	</ResourceParams>
</Context>

This is my Myapp/WEB-INF/web.xml entry,

<resource-ref>
   <description>DS Connection</description>
      <res-ref-name>jdbc/UserDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
</resource-ref>


...and this is the error,

ERROR - ServletException in '/layouts/classicLayout.jsp': Cannot create JDBC 
driver of class '' for connect URL 'null'
javax.servlet.ServletException: Cannot create JDBC driver of class '' for 
connect URL 'null'
	at 
org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:880)
	at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)


For whatever reason it doens't seem to be loading the driver class.  This is 
the line causing the error,

		Connection conn = ds.getConnection();

I'm using Tomcat 5.5.4(if JDNI is not the best way to acces a database from 
a Tiles Controller, what is, what is?)

  (I can query by other means using the JDBC driver which is located in 
...tomcat/common/lib/, so it's JDNI that giving me the problem.)


Thanks,
Jim,



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


Re: I want to use data source defined in stuts-config.xml in my bean. How can I do it ?

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Hmm ... I suggest you don't use the data source unless you are forced to 
by a legacy application. The data-source element has been deprecated. 
Instead create and access your data source through means provided by 
your container (e.g. JNDI).  Take a look at this page
http://struts.apache.org/faqs/database.html.

Amit Gupta wrote:
> Hi dear,
> 
>  
> 
> I am struts newbie. I want to use data source defined in stuts-config.xml in my bean. How can I do it ?
> 
>  
> 
> Please help.
> 
>  
> 
> Amit Gupta   
> 
> 


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