tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twcTC <twc7183590...@earthlink.net>
Subject Re: configure data source
Date Sun, 18 Apr 2004 02:06:57 GMT
I have the same problem. please help.
===============================detail info==============
hello all,

I need help.
I am using jwsdp-1.3. I am trying to connect to oracle 8.1.5 database using DataSource.
I get sqlexception 
"java.sql.SQLException: Cannot load JDBC driver class".

I have put oracle jdbc classes12.zip into /common/lib/classes12.jar.
(I rename classes12.zip to classes12.jar)

Thank you very much.
It took me a lot of time.

--Tony

The following is config and code files.

conf/server.xml
========
<?xml version='1.0' encoding='utf-8'?>
<Server className="org.apache.catalina.core.StandardServer" debug="0"
port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
debug="0"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
debug="0"/>
  <GlobalNamingResources>
    <Environment description="Absolute Pathname of the JWSDP Installation"
name="jwsdp.home" override="true" type="java.lang.String"
value="D:\jwsdp13"/>
    <Environment name="simpleValue" override="true"
type="java.lang.Integer" value="30"/>
    <Resource auth="Container" description="User database
that can be updated and saved" name="UserDatabase" scope="Shareable"
type="org.apache.catalina.UserDatabase"/>
    <Resource name="jdbc/myoracle" scope="Shareable"
type="javax.sql.DataSource"/>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>
    <ResourceParams name="jdbc/myoracle">
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>4</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>tiger</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:oracle:thin:@127.0.0.1:1521:dellorcl</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>oracle.jdbc.driver.OracleDriver</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>scott</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>
  <Service className="org.apache.catalina.core.StandardService"
debug="0" name="Java Web Services Developer Pack">
    <Connector className="org.apache.coyote.tomcat5.CoyoteConnector"
acceptCount="100" bufferSize="2048" clientAuth="false"
compression="off" connectionLinger="-1" connectionTimeout="20000"
connectionUploadTimeout="300000" debug="0" disableUploadTimeout="true"
enableLookups="true" keepAlive="true" maxKeepAliveRequests="100"
maxProcessors="100" minProcessors="5" port="8080"
protocol="HTTP/1.1" protocolHandlerClassName="org.apache.coyote.http11.Http11Protocol"
proxyPort="0" redirectPort="8443" scheme="http"
secure="false" serverSocketTimeout="0" tcpNoDelay="true"
tomcatAuthentication="true" xpoweredBy="true">
    </Connector>
    <Engine className="org.apache.catalina.core.StandardEngine"
backgroundProcessorDelay="10" baseDir="D:\jwsdp13" debug="0"
defaultHost="localhost" domain="Catalina" name="Catalina">
      <Host className="org.apache.catalina.core.StandardHost" appBase="webapps"
autoDeploy="true" backgroundProcessorDelay="-1" configClass="org.apache.catalina.startup.ContextConfig"
contextClass="org.apache.catalina.core.StandardContext" debug="0"
deployOnStartup="true" deployXML="true" domain="Catalina"
errorReportValveClass="org.apache.catalina.valves.ErrorReportValve"
liveDeploy="true" name="localhost" unpackWARs="false"
xmlNamespaceAware="false" xmlValidation="false">
        <Valve className="org.apache.catalina.authenticator.SingleSignOn"
debug="0"/>
      </Host>
      <Logger className="org.apache.catalina.logger.FileLogger"
debug="0" directory="logs" prefix="jwsdp_log."
suffix=".txt" timestamp="true" verbosity="1"/>
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
debug="0" resourceName="UserDatabase" validate="true"/>
      <Valve className="org.apache.catalina.valves.AccessLogValve"
debug="0" directory="logs" fileDateFormat="yyyy-MM-dd"
pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="access_log."
resolveHosts="false" rotatable="true" suffix=".txt"/>
    </Engine>
  </Service>
</Server>
========

/hello1/build/Wen-inf/web.xml
=========================
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <display-name>hello1</display-name>
  <servlet>
    <display-name>GreetingServlet</display-name>
    <servlet-name>GreetingServlet</servlet-name>
    <servlet-class>servlets.GreetingServlet</servlet-class>
  </servlet>
  <servlet>
    <display-name>ResponseServlet</display-name>
    <servlet-name>ResponseServlet</servlet-name>
    <servlet-class>servlets.ResponseServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>GreetingServlet</servlet-name>
    <url-pattern>/greeting</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ResponseServlet</servlet-name>
    <url-pattern>/response</url-pattern>
  </servlet-mapping>
<resource-ref>
 <description>Oracle Datasource example</description>
 <res-ref-name>jdbc/myoracle</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>
</web-app>
=========================

/Catalina/localhost/hello1.xml
=======================
        <Context className="org.apache.catalina.core.StandardContext"
backgroundProcessorDelay="-1" cachingAllowed="true" 
charsetMapperClass="org.apache.catalina.util.CharsetMapper" configFile="D:\jwsdp13\conf\Catalina\localhost\hello1.xml"
cookies="true" crossContext="false" debug="0"
displayName="hello1" docBase="D:/jwsdp13/jwstutorial13/examples/web/hello1/build"
domain="Catalina" engineName="Catalina" j2EEApplication="none"
j2EEServer="none" lazy="true" managerChecksFrequency="6"
path="/hello1" privileged="false" reloadable="false"
startupTime="30" swallowOutput="false" tldScanTime="0"
useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
          <Resource auth="Container" description="Oracle
Datasource example" name="jdbc/myoracle" scope="Shareable"
type="javax.sql.DataSource"/>
        </Context>
=======================

here are sql code
GreetingServlet.java
=====================
package servlets;

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * This is a simple example of an HTTP Servlet.  It responds to the GET
 * method of the HTTP protocol.
 */
public class GreetingServlet extends HttpServlet { 

    public void doGet (HttpServletRequest request,
                       HttpServletResponse response)
                        throws ServletException, IOException
 {
//db
String sResult="Failed";

try{
Context initContext = new InitialContext(); 
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle"); 
Connection conn = ds.getConnection(); 
if(conn!=null){
 sResult="Ok";
}
}catch(Exception e){
	sResult=e.toString();
}
//db

      response.setContentType("text/html");
      response.setBufferSize(8192);
      PrintWriter out = response.getWriter();

      // then write the data of the response
      out.println("<html>" +
                  "<head><title>Hello</title></head>");

   // then write the data of the response
      out.println("<body  bgcolor=\"#ffffff\">" +
         "<img src=\"duke.waving.gif\" alt=\"Duke
waving\">" + 
         "<h2>Hello, "+sResult+" my name is Duke. What's yours?</h2>"
+
         "<form method=\"get\">" +
         "<input type=\"text\" name=\"username\"
size=\"25\">" +
         "<p></p>" +
         "<input type=\"submit\" value=\"Submit\">"
+
         "<input type=\"reset\" value=\"Reset\">"
+
         "</form>");

      String username = request.getParameter("username");
      if ( username != null && username.length() > 0 ) {
            RequestDispatcher dispatcher =
               getServletContext().getRequestDispatcher("/response");
                                    
            if (dispatcher != null)
            dispatcher.include(request, response);

      }
      out.println("</body></html>");
      out.close();
    }

    public String getServletInfo() {
        return "The Hello servlet says hello.";

    }
 }
=======================
======================================detail info============================




-----Original Message-----
From: Niraj Alok <niraj@emacmillan.com>
Sent: Apr 16, 2004 8:04 PM
To: Tomcat Users List <tomcat-user@jakarta.apache.org>
Subject: configure data source


 Hi All,


 I am trying to obtain a connection using DataSource
 in Tomcat5 .

 I get the following error :

 org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of
 class '' for connect URL 'null', cause:

 java.sql.SQLException: No suitable driver



 My source code is :

     Context ctx = new InitialContext();

     if (ctx == null)

         throw new Exception("No context got! Exception");

     System.out.println("got ctx");

     DataSource ds =

         (DataSource) ctx.lookup("java:comp/env/jdbc/hypersonic");


     if(ds == null)

         throw new Exception("No ds got! Exception");

     else

     {

     System.out.println("got ds");

     Connection con = ds.getConnection();

     if(con != null)

      ....
      ...
     }


 My server.xml looks like :

<GlobalNamingResources>

<Environment name="simpleValue" type="java.lang.Integer" value="30"/>

<Resource auth="Container" description="User database that can be updated
and saved" name="UserDatabase" type="org.apache.catalina.UserDatabase"/>

<Resource name="hypersonic" type="javax.sql.DataSource"/>

<ResourceParams name="UserDatabase">

<parameter>

<name>factory</name>

<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>

</parameter>

<parameter>

<name>pathname</name>

<value>conf/tomcat-users.xml</value>

</parameter>

</ResourceParams>

<ResourceParams name="hypersonic">

<parameter>

<name>maxWait</name>

<value>5000</value>

</parameter>

<parameter>

<name>maxActive</name>

<value>20</value>

</parameter>

<parameter>

<name>password</name>

<value></value>

</parameter>

<parameter>

<name>url</name>

<value>jdbc:hsqldb:hsql://localhost:1701</value>

</parameter>

<parameter>

<name>driverClassName</name>

<value>org.hsqldb.jdbcDriver</value>

</parameter>

<parameter>

<name>maxIdle</name>

<value>2</value>

</parameter>

<parameter>

<name>username</name>

<value>sa</value>

</parameter>

</ResourceParams>

</GlobalNamingResources>



   My web.xml contains:



   <resource-ref>

   <description>DB Connection</description>

   <res-ref-name>jdbc/hypersonic</res-ref-name>

   <res-type>javax.sql.DataSource</res-type>

   <res-auth>Container</res-auth>

   </resource-ref>



   Even if i comment this entry in web.xml the error is still the same.



   Can any one please tell me what am I doing wrong??

   Regards,
   Niraj




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



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


Mime
View raw message