struts-user mailing list archives

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

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
4.0.3.

Here is what I've done so far

1. Move the Oracle Drivers (classes12.zip) 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

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


3. Added the following codes within the <Context> </Context> tag of
<TOMCAT_HOME>\conf\server.xml

<Resource name="jdbc/ora" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/ora">
<parameter>
<name>user</name>
<value>system</value>
</parameter>
<parameter>
<name>password</name>
<value>manager</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:oracle:oci8:@oracle8</value>
</parameter>
</ResourceParams> 

4. try to make connection within my JSP

<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ 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.

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


-----Original Message-----
From: maarten roosendaal [mailto:mroosendaal@yahoo.com]
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
Action-class. 

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
here.

Maarten

--- Vikramjit Singh <vikramjits@gtllimited.com> 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:  
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

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

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


Mime
View raw message