tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sasha Borodin <sa...@whoissasha.com>
Subject Re: configuring sqlserver datasource
Date Thu, 28 Aug 2003 18:14:44 GMT
I don't specify MS's factory, so it uses the default one I think;  this
works for me:

    <Resource auth="Container" name="jdbc/WebsiteBenchmark"
scope="Shareable" type="javax.sql.DataSource"/>
    
    <ResourceParams name="jdbc/WebsiteBenchmark">
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>4</value>
      </parameter>
      <parameter>
        <name>driverName</name>
        <value>jdbc:microsoft:sqlserver</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:microsoft:sqlserver://you.sql.server:1433</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>password</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>username</value>
      </parameter>
    </ResourceParams>

On 8/28/03 1:44, "erik.itter@bbraun.com" <erik.itter@bbraun.com> wrote:

> hi,
> 
> i want to set up a DataSource for MS SQLServer 2000 at Tomcat 5.0.9 but
> the DataSource is allways null - any hints welcome
> 
> 
> server.xml
> 
> <Server port="8005" shutdown="SHUTDOWN" debug="0">
> 
> 
> <!-- Comment out these entries to disable JMX MBeans support -->
> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
>           debug="0"/>
> <Listener 
> className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
>           debug="0"/>
> 
> <!-- Global JNDI resources -->
> <GlobalNamingResources>
> 
>   <!-- Test entry for demonstration purposes -->
>   <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
> 
>   <!-- Editable user database that can also be used by
>        UserDatabaseRealm to authenticate users -->
>   <Resource name="UserDatabase" auth="Container"
>             type="org.apache.catalina.UserDatabase"
>      description="User database that can be updated and saved">
>   </Resource>
>   <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>
> 
> </GlobalNamingResources>
> <Service name="Catalina">
>   <Connector 
> port="8080"               maxThreads="150" minSpareThreads="25"
> maxSpareThreads="75"
>              enableLookups="false" redirectPort="8443" acceptCount="100"
>              debug="0" connectionTimeout="20000"
>              disableUploadTimeout="true" />
>   <Connector port="8009"
>              enableLookups="false" redirectPort="8443" debug="0"
>              protocol="AJP/1.3" />
>   <Engine name="Catalina" defaultHost="localhost" debug="0">
>     <Logger className="org.apache.catalina.logger.FileLogger"
>             prefix="catalina_log." suffix=".txt"
>             timestamp="true"/>
>     <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
>                debug="0" resourceName="UserDatabase"/>
>     <Host name="localhost" debug="0" appBase="webapps"
>      unpackWARs="true" autoDeploy="true">
>       <Logger className="org.apache.catalina.logger.FileLogger"
>                directory="logs"  prefix="localhost_log." suffix=".txt"
>           timestamp="true"/>
>       <Context path="/WebsiteBenchmark" docBase="WebsiteBenchmark"
> debug="5" reloadable="true" crossContext="true">
> 
>         <Logger className="org.apache.catalina.logger.FileLogger"
> prefix="localhost_WebsiteBenchmark_log." suffix=".txt" timestamp="true"/>
> 
>         <Resource name="jdbc/WebsiteBenchmark" auth="Container"
> type="javax.sql.DataSource"/>
> 
>         <ResourceParams name="jdbc/WebsiteBenchmark">
>           <parameter>
>             <name>factory</name>
> <value>com.microsoft.jdbcx.sqlserver.SQLServerDataSourceFactory</value>
>           </parameter>
> 
>           <parameter>
>             <name>maxActive</name>
>             <value>100</value>
>           </parameter>
> 
>           <parameter>
>             <name>maxIdle</name>
>             <value>30</value>
>           </parameter>
> 
>           <parameter>
>             <name>maxWait</name>
>             <value>10000</value>
>           </parameter>
> 
>           <parameter>
>             <name>username</name>
>             <value>websitebenchmark</value>
>           </parameter>
>           <parameter>
>             <name>password</name>
>             <value>redheader</value>
>           </parameter>
> 
>           <parameter>
>             <name>driverClassName</name>
>             <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
>           </parameter>
> 
>           <parameter>
>             <name>url</name>
>             <value>jdbc:microsoft:sqlserver://212.0.21.223:1433</value>
>           </parameter>
>         </ResourceParams>
>       </Context>
> 
> 
>     </Host>
> 
>   </Engine>
> 
> </Service>
> 
> </Server>
> 
> 
> web.xml
> 
> <?xml version="1.0" ?>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
> 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
> 
> 
> <web-app>
> 
>   <display-name>B. Braun Melsungen AG - Website Benchmark</display-name>
>   <description>monitors website performance</description>
> 
>   <servlet> 
>     <servlet-name>WebsiteBenchmark</servlet-name>
> 
> <servlet-class>com.bbraun.websitebenchmark.WebsiteBenchmark</servlet-class>
>   </servlet> 
> 
>   <servlet-mapping>
>     <servlet-name>WebsiteBenchmark</servlet-name>
>           <url-pattern>/*</url-pattern>
>       </servlet-mapping>
> 
>       <welcome-file-list>
>               <welcome-file>index.jsp</welcome-file>
>       </welcome-file-list>
> 
>       <error-page>
>               <error-code>404</error-code>
>               <location>/error.jsp</location>
>       </error-page>
> 
>       <resource-ref>
>               <description>
>               Website Benchmark DataSource
>               </description>
>               <res-ref-name>
>               jdbc/WebsiteBenchmark
>               </res-ref-name>
>               <res-type>
>               javax.sql.DataSource
>               </res-type>
>               <res-auth>
>               Container
>               </res-auth>
>       </resource-ref>
> </web-app>
> 
> 
> 
> code
> 
>       private void testDB(HttpServletResponse res) {
> 
>               PrintWriter out = null;
>               try {
>                       out = res.getWriter();
>               } catch (IOException e1) {
>                       // TODO Auto-generated catch block
>                       e1.printStackTrace(out);
>               }
>               out.println("testDB");
>               out.flush();
> 
>               DataSource ds = null;
>               InitialContext ctx = null;
>               try {
>                       ctx = new InitialContext();
>               } catch (NamingException e) {
>                       // TODO Auto-generated catch block
>                       e.printStackTrace(out);
>               }
>               try {
>                       out.println("context: "+ctx.toString()+",
> "+ctx.getNameInNamespace());
>               } catch (NamingException e2) {
>                       // TODO Auto-generated catch block
>                       e2.printStackTrace(out);
>               }
>               out.flush();
>               try {
>                       ds =
> (DataSource)ctx.lookup("java:comp/env/jdbc/WebsiteBenchmark");
>               } catch (NamingException e) {
>                       // TODO Auto-generated catch block
>                       e.printStackTrace(out);
>               }
>               out.println(ds);
>               out.flush();
>               try {
>                       Connection con = ds.getConnection();
>                       Statement stmt = con.createStatement();
>                       ResultSet rs = stmt.executeQuery("select * from
> testvalues");
>                       out.write("results returned from test query");
>                       ResultSetMetaData md = rs.getMetaData();
>                       out.write("cols: "+md.getColumnCount());
>               } catch (SQLException e) {
>                       // TODO Auto-generated catch block
>                       e.printStackTrace(out);
>               }
>               out.flush();
>               out.close();
>       }
> 
> output
> 
> testDB
> context: javax.naming.InitialContext@102b2b6, java:
> null
> 


Mime
View raw message