struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vikramjit Singh <>
Subject RE: how to get connection from my normal servlet
Date Thu, 20 Jun 2002 06:41:20 GMT

I am trying to use DataSource, well this question might not be exactly
related to struts, but is sure a step towards struts. I am using Tomcat

Here is what I've done so far

1. Move the Oracle Drivers ( into <TOMCAT_HOME>\lib and 

<TOMCAT_HOME>\common\lib directories and rename them to classes12.jar

2. Added the following codes to my webapp's web.xml


3. Added the following codes within the <Context> </Context> tag of

<Resource name="jdbc/ora" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/ora">

4. try to make connection within my JSP

<%@ page import="*" %>
<%@ page import="*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.naming.*" %>

try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/ora");
Connection conn1 = ds.getConnection();
out.println("Win2000 Oracle Connected!<br>");
catch (SQLException E) {
out.println("<br>unable to get connection on ora !"); 
out.println("<br>SQLException: " + E.getMessage());
out.println("<br>SQLState: " + E.getSQLState());
out.println("<br>VendorError: " + E.getErrorCode());

Results :
unable to get connection on ora ! 
SQLException: Cannot load JDBC driver class 'null' 
SQLState: null 
VendorError: 0

If this problem is solved, then sure getting connection from the action
class will not be a problem.

Vikramjit Singh,
Systems Engineer,
GTL Ltd.
Ph. 7612929-1031

-----Original Message-----
From: maarten roosendaal []
Sent: Wednesday, June 19, 2002 12:26 AM
To: Struts Users Mailing List
Subject: Re: how to get connection from my normal servlet

We are also using JBoss for EJB development. In the
jboss.xml you can create a connectionpool which you
can use to create a Connection / DataSource within an

There are some examples on how to do this with Tomcat
where you define a connectionpool in the server.xml
but others with me have problems with the
InitialContext and retrieving the Connection (in
combination with Struts).

There is always the easy way of doing a hardcode
connection in an Action-class by providing the url,
password and username when building the connection.

If you find a solution for the second issue, post it


--- Vikramjit Singh <> wrote:
> good day to all,
> I am trying to use struts in my application. I have
> my own connection
> pooling, in which one servlet is loaded on start-up.
> I put the connection in
> the ServletContext, and from the servlet i get the
> connection. 
> Thats the old way.
> Now with struts, am sending the form parameters to
> the ActionServlet which
> is taking the values from the ActionServlet, but how
> do i get the connection
> for the database?. I have been going through some
> examples related to struts
> and database, seems like i have to used
> DataSourceName. Is that the only
> option, cant i use the traditional way of getting
> the connection and
> inserting into the database.
> Thanking in advance.
> Regards,
> Vikramjit Singh,
> Systems Engineer,
> GTL Ltd.
> Ph. 7612929-1031
> --
> To unsubscribe, e-mail:  
> <>
> For additional commands, e-mail:
> <>

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message