Results 1 to 1 of 1
  1. #1
    Join Date
    Dec 2002
    Posts
    3

    Question Unanswered: Tomcat JNDI + SQL Server

    I am trying to lookup a datasource in a servlet for SQLServer from the JNDI tree using tomcat 4.1 LE. However, I get the following exception:

    javax.naming.NamingException: Cannot create resource instance

    Here is what I think is the revelant info. If anyone has any idea I would really appreciate it, google is turning up empty. I have done this before with BEA without a problem.

    I have a ODBC connection with the name MustangGT that is working fine with my ASP app. I have also tried this using the JdbcOdbc bridge but still get the same error.

    Thanks,
    --chad

    Begin server.xml -------------------------------------------------------
    <Resource name="MustangGT" scope="Shareable" type="javax.sql.DataSource"/>
    <ResourceParams name="MustangGT">
    <parameter>
    <name>url</name>
    <value>jdbc:microsoft:sqlserver://summerq:1433;DatabaseName=MustangGT</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>thePassword</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>com.microsoft.jdbc.sqlserver.SQLServerDrive r</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>theUserName</value>
    </parameter>
    </ResourceParams>

    End server.xml ---------------------------------------------------------------

    Begin servlet code -----------------------------------------------------------

    try {
    Context ctx = new InitialContext();
    Context envCtx = (Context)ctx.lookup("java:comp/env");
    DataSource ds = (DataSource)envCtx.lookup("MustangGT");
    Connection con = ds.getConnection();
    Statement stmt = con.createStatement();
    ResultSet res = stmt.executeQuery( "SELECT * FROM PROJECTS" );
    while( res.next() ) {
    String col2 = res.getString( 1 );
    writeHTML( col2 + "<br>", response );
    }
    res.close();
    stmt.close();
    con.close();
    } catch( Exception e ) {
    e.printStackTrace();
    }

    End servlet code---------------------------------------------------------------
    Last edited by white_2kgt; 12-13-02 at 00:45.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •