Hi,

I studied something about Sybase ASA and here are my pieces of knowledge:
- ASA is, unlike ASE, ODBC based insted of TDS
- the JDBC drivers are generic JDBC-to-ODBC bridge and can be used to
access _any_ database throw ODBC
- the JDBC drivers are not freely downloadable (I didn't find any)

- You can access ASA also throw jConnect (TDS based Sybase's JDBC drivers)
This solution is functional but the speed (power) is less -- Sybase
does not recomand to use jConnect drivers.

So, I tried to use my ASE under Tomcat (Currently, I'm successfuly
using PostgreSQL). The following solution works fine under Tomcat
standalone and Tomcat under Eclipse.

Small HOWTO for Tomcat 5.5.15/jdk1.5.0_06/Linux:
1. Locate your existing JDBC driver, or try use jConnect
(http://www.sybase.com/products/middleware/jconnectforjdbc)
2. Copy the driver jar(s) into ${CATALINA_HOME}/common/lib
3. Create your META-INF/context.xml
4. Make the resource references in the WEB-INF/web.xml
5. Use the data source(s) in your code

I saw the `Cannot load JDBC driver class' and it seens the drivers
must be in the common/lib directory.

Finally, here is my context.xml, web.xml and example lines using the database

Hope this helps

PETR


META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
        <Resource
                auth="Container"
                scope="Shareable"
                description="Logging database connection"
                name="jdbc/project/logger"
                type="javax.sql.DataSource"
                driverClassName="org.postgresql.Driver"
                url="jdbc:postgresql://127.0.0.1:5432/project"
                username="uname"
                password="password6"
                maxIdle="20"
                maxWait="5000"
                maxActive="20"
                validationQuery="SELECT version();" />
        <Resource
                auth="Container"
                scope="Shareable"
                description="Test connection to the Sybase ASE server"
                name="jdbc/project/sybase"
                type="javax.sql.DataSource"
                driverClassName="com.sybase.jdbc3.jdbc.SybDriver"
                url="jdbc:sybase:Tds:ws:5000"
                username="sa"
                password=""
                maxIdle="20"
                maxWait="5000"
                maxActive="20"
                validationQuery="" />
</Context>


WEB-INF/web.xml
...
        <resource-ref>
                <description>PROJECT client</description>
                <res-ref-name>jdbc/project/logger</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
        </resource-ref>
        <resource-ref>
                <description>PROJECT client</description>
                <res-ref-name>jdbc/project/sybase</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
        </resource-ref>

</web-app>

SAMPLE/code
...
                        final Context initCtx = new InitialContext();
                        final Context envCtx = (Context) 
initCtx.lookup("java:comp/env");

                        final DataSource dataSource = (DataSource) 
envCtx.lookup(databaseName);

                        final Connection conn = dataSource.getConnection();

                        final PreparedStatement stmt = conn.prepareStatement(
                                        "INSERT INTO access_log (acsl_account, 
acsl_object) " +
                                        "VALUES (NULL, ?)");

                        final HttpServletRequest request = 
getContentManager().getRequest();

                        final String log = request.getRequestURL().toString() +
                                        " -- " + request.getRemoteHost() + ":" 
+ request.getRemotePort() +
                                        " -- " + parseRequestHeaders(request);

                        stmt.setString(1, log);

                        stmt.execute();

                        stmt.close();

                        conn.close();

                        //

                        final DataSource ds = (DataSource) 
envCtx.lookup("jdbc/project/sybase");

                        final Connection cn = ds.getConnection();

                        Statement st2 = cn.createStatement();
                        st2.execute("USE test");
                        st2.close();

                        cn.close();

On 3/3/06, Tom Bednarz <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Thanks for your help. It brought me one step further but did not yet
> solve the problem! It looks like the context.xml is mandatory. I moved
> the configuration from the server.xml to the context.xml. The error
> message changed as follows:
>
> org.apache.jasper.JasperException: Unable to get connection, DataSource 
> invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC 
> driver class 'ianywhere.ml.jdbcodbc.IDriver'"
>         
> org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
>         
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
>         
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
>
> This means it does not find the driver jar file. I put it in all
> possible directories (lib directories of the webapp, tomcats common/lib
> and shared/lib) but all without success. Do I have to set a CLASSPATH
> somewhere??
>
> Tom
>
>
> Hadraba Petr wrote:
>
> >Hi,
> >
> >I'm not using Sybase under Tomcat; I have PostgreSQL...
> >
> >Eclipse? My configuration is, Eclipse does not modify Tomcat
> >configuration (this is the default)
> >
> >In your WebContent under META-INF create context.xml with the
> ><Resource ... /> definition. The <Context /> element does not require
> >any attributes:
> ><Context>
> >  <Resource ... your="attributes" ... />
> ></Context>
> >
> >And finaly, place the JDBC driver JAR into your WEB-INF lib.
> >
> >Catalina will automaticaly load your driver. My configuration is
> >working properly.
> >
> >This configuration is working for me fine!
> >
> >JNDI names? Look at the JNDI section in the J2EE Tutorial in the Sun's
> >web site. The examples are very helpful.
> >
> >There is also another question:
> >It's good solution to place JDBC driver into the webapp's lib directory?
> >
> >
> >Hope it helps
> >
> >PETR
> >
> >PS.: My Adaptive Server Enterprise 15 is working good, but not under
> >Tomcat; it's standalone application... The initialization, driver URL
> >was taken from the Sybase's JDBC documentation on their web sites.
> >
> >
> >On 3/3/06, Tom Bednarz <[EMAIL PROTECTED]> wrote:
> >
> >
> >>I try to configure a JDBC DataSource for my Adaptive Server Anywhere 9
> >>database. Unfortunately without any success so far!
> >>I use Tomcat 5.5.18.
> >>
> >>The error is well known and looks as follows:
> >>
> >>org.apache.jasper.JasperException: Unable to get connection, DataSource
> >>invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create
> >>JDBC driver of class '' for connect URL 'null'"
> >>    
> >> org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
> >>org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
> >>
> >>org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
> >>org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
> >>    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> >>
> >>
> >>I use the JDBCODBC driver to connect. Here is the configuration:
> >>
> >>server.xml
> >>
> >>    <Resource
> >>      name="jdbc/MyService"
> >>      type="javax.sql.DataSource"
> >>      password="sql"
> >>      driverClassName="ianywhere.ml.jdbcodbc.IDriver"
> >>      maxIdle="2"
> >>      maxWait="5000"
> >>      validationQuery="select * from CodeTable"
> >>      username="dba"
> >>      url="jdbc:odbc:dsn=MyService"
> >>      maxActive="50"
> >>      removeAbandoned="true"
> >>      removeAbandonedTimeout="60"
> >>      logAbandoned="true"/>
> >>
> >>Web.xml
> >>
> >>  <resource-ref>
> >>      <description>Database connection</description>
> >>      <res-ref-name>jdbc/MyService</res-ref-name>
> >>      <res-type>javax.sql.DataSource</res-type>
> >>      <res-auth>Container</res-auth>
> >>  </resource-ref>
> >>
> >>Note: I currently do NOT deplay using a WAR file since I use Eclipse as
> >>develpment environment to debug etc. So I do NOT have an application
> >>specific context.xml file at the moment.
> >>
> >>Could anybody please explain what needs to be put into the name
> >>property? It seems that jdbc/ is mandatory but what needs to follow the
> >>slash is not clear to me! Is it the ODBC datasource name, the database
> >>name or any choosen name??
> >>
> >>Many thanks for your help.
> >>
> >>Tom
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to