Thank you in advance
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/petrDB");
out.println("datasource:"+ds);
returns the proper name (test jdbc/petrDB)
taken from web.xml
<resource-ref>
<description>test jdbc/petrDB</description>
...
BUT there is next error
at line:
Connection con = ds.getConnection();
error: java.sql.SQLException: No suitable driver
If you have ANY idea please let me know.
Direct code works properly
----------------------------------------------------------------------------
------
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver" ;
String url =
"jdbc:microsoft:sqlserver://parallel00;user=test1;Password=testa;DatabaseNam
e=petr_dev1" ;
Connection conDB = null;
Class.forName(driver);
conDB = DriverManager.getConnection(url);
Petr
so I have now this content in my files:
--------------------------------------------------------------------------
-------------------- hello1.jsp
--------------------------------------------------------------------------
<%@page contentType="text/html"%>
<%@page import="java.sql.*"%>
<%@page import="javax.sql.*"%>
<%@page import="javax.naming.Context"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.NamingException"%>
<%@page import="com.microsoft.jdbcx.sqlserver.SQLServerDataSource"%>
<html>
<head><title>JSP Page</title></head>
<body>
test start
<%
out.println("<BR>test<BR>");
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/petrDB");
out.println("datasource:"+ds);
Connection con = ds.getConnection();
--------------------------------------------------------------------------
-------------------- web.xml (located in subdir /WEB-INF of directory where
is hello1.jsp)
--------------------------------------------------------------------------
<resource-ref>
<description>test jdbc/petrDB</description>
<res-ref-name>jdbc/petrDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
--------------------------------------------------------------------------
-------------------- server.xml
--------------------------------------------------------------------------
<Resource name="jdbc/petrDB" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/petrDB">
<parameter>
<name>database</name><value>petr_dev1</value>
</parameter>
<parameter>
<name>driverClassName</name><value>com.microsoft.jdbc.sqlserver.SQLServerDri
ver</value>
</parameter>
<parameter>
<name>driverName</name><value>jdbc:microsoft:sqlserver://parallel00;user=tes
t1;Password=testa;DatabaseName=petr_dev1</value>
</parameter>
<parameter>
<name>user</name><value></value>
</parameter>
<parameter>
<name>password</name><value></value>
</parameter>
</ResourceParams>
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
ConnectionPoolDataSource ds =
(ConnectionPoolDataSource)envCtx.lookup("jdbc/petrDB");
PooledConnection x = ds.getPooledConnection("usr","pwd");
Connection conDB1 = x.getConnection();
You need to create datasource using
com.microsoft.jdbcx.sqlserver.SQLServerDataSource class.
Thanks,
Sridhar Paladugu
Microsoft Developer Support
JDBC Webdata
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order
your FREE Security Tool Kit, please visit
<http://www.microsoft.com/security>.
On the line where I'm trying to do the lookup:
com.microsoft.jdbcx.sqlserver.SQLServerDataSource ds =
(com.microsoft.jdbcx.sqlserver.SQLServerDataSource)envCtx.lookup("jdbc/nutro
sDB");
I get this error:
javax.naming.NamingException: Cannot create resource instance
at
org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.
java:167)
at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:299)
at org.apache.naming.NamingContext.lookup(NamingContext.java:834)
at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
Any idea on things to check? Here is the whole code snippet:
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
System.out.println(" About to get ds.");
com.microsoft.jdbcx.sqlserver.SQLServerDataSource ds =
(com.microsoft.jdbcx.sqlserver.SQLServerDataSource)envCtx.lookup("jdbc/nutro
sDB");
System.out.println("About to get pooledconnection.");
PooledConnection x = ds.getPooledConnection("usr","pwd");
System.out.println("About to get connection.");
Connection conDB1 = x.getConnection();
I have the same problems , and I've noticed a couple of interesting
things:
1) Tomcat seems to be passing in the JDBC resources fine, it's only
when you actually do a lookup() that it returns NULL. This *seems* to
imply that it may be a CLASSPATH issue (perhaps?)
2) Tomcat seems to behave slightly differently depending on how you
start it up - if you start it up using the shortcut to the
bootstrap.jar, it doesnt raise a naming excaption, but if you just run
startup.bat, it does (this is what happens on my setup - I know Im
missing a fundamental understanding of how the whole thing works
including CLASSPATH issues, but hey Im new to this :-) )
3) If you run Tomcat in JDB, you can see the boot and working
classpath and visible classes. It would be helpful if someone who has
it working could do this, and we can compare it with our setups. Just
run catalina -debug from the /bin directory.
Ive been wrestling with this for a while, I _think_ that I've got it
narrowed down to CLASSPATH issues, but I'm still not sure .... anyone
else got this working?
Cheers
Rory
"Sean LeBlanc" <se...@nutros.com> wrote in message news:<ejhPfai5BHA.1892@tkmsftngp04>...
On the Tomcat mailing list, someone had suggested putting this in the
server.xml, along with other Resource info:
<parameter>
<name>factory</name><value>com.microsoft.jdbcx.sqlserver.SQLServerDataSource
Factory</value>
</parameter>
Also, in web.xml, this was something that was suggested. Embedded inside the
resource-ref:
<res-type>com.microsoft.jdbcx.sqlserver.SQLServerDataSource</res-type>
Of course, I still don't have it working, and the error message hasn't
changed at all, so take it with a large grain of salt...
As for CLASSPATH stuff, I just have ms*.jar tacked on in the startup shell
script...I had to do that for the "vanilla connect" to work, so I would hope
that Tomcat would be able to do lookup with this same info in CLASSPATH. I
put the javax extension jar in my /jre/lib/ext/ dir, do you have it set up
the same way?
Yes, I have the MS .jar files in $JAVA_HOME/jre/lib/ext - I've tried
putting the .jar files in various places , but no joy - I'll give your
suggestion a go and see if it makes any difference.
Cheers
rory
"Sean LeBlanc" <se...@nutros.com> wrote in message news:<uKpbJru5BHA.2116@tkmsftngp04>...
"Rory Winston" <rory.w...@telewest.co.uk> wrote in message
news:22e0c051.02042...@posting.google.com...
Okay, but what do you suggest as a replacement? If I try just
com.microsoft.jdbcx.sqlserver.SQLServerDataSource in my web.xml (Factory
wasn't in my code as posted below), I get the same error as posted
previously.
Let me plead with those that have it working under Tomcat to post their
server.xml, their web.xml from context directory, and working code. Thanks!
"Sean LeBlanc" <se...@nutros.com> wrote in message
news:uAfWibu6BHA.2156@tkmsftngp07...
I have not understood what tomcat is doing with driver. I have tested this
datasource class using openLDAP thru JNDI and successfully bind the datasource
in the directory and used it for our poolmanager(i wrote one to use internal
testing).This has no problem with either weblogic or websphere application
servers. Currently i do not have tomcat installed. I would appriciate if any
one can provide some inputs regarding how tomcat creates datasources and bind
them in its JNDI environment.
Thanks for every one participating in this community.
"Sridhar Paladugu[MS]" <sr...@online.microsoft.com> wrote in message
news:zGE1euX7BHA.1700@cpmsftngxa07...
"Sridhar Paladugu[MS]" <sr...@online.microsoft.com> wrote in message
news:g52Kzu77BHA.1532@cpmsftngxa08...
> Hi,
>
> I have looked in to tomcat documents and i found that tocat is sending the
> SQLServerDataSourceFactory name as Reference object. Which i believe wrong
for
> this driver.
>
> let us consider my server.xml file is as follows;
>
> <ResourceName="jdbc/northwind" auth=Container"
> type="javax.sql.SQLServerDataSource">
> <ResourceParams name="jdbc/northwind">
>
>
<parameter><name>factory</name><value>com.microsoft.jdbcx.sqlserver.SQLServe
rDat
> aSourceFactory</value></parameter>
>
>
<parameter><name>driverClassName</name><value>com.microsoft.jdbcx.sqlserver.
SQLS
> erverDataSource</value></parameter>
>
<parameter>name>serverName</name><value>wdserver</value></parameter>
> <parameter>name>portNumber</name><value>1433</value></parameter>
>
<parameter>name>databaseName</name><value>pubs</value></parameter>
> <parameter>name>user</name><value>sridhar</value></parameter>
>
<parameter>name>password</name><value>password</value></parameter>
>
<parameter>name>selectMethod</name><value>cursor</value></parameter>
> </ResourceParams>
>
>
> So when we try to create the datasource by calling lookup method, the
tomcat
> context is calling the
>
> SQLServerDataSource.getObjectInstance(Object obj, Name name, Context ctx,
> Hashtable env) ; method using the following values;
>
> obj =
com.microsoft.jdbcx.sqlserver.SQLServerDataSourceFactory
> , but the driverfactory class expecting the obj value as
> com.microsoft.sqlServer.SQLServerDataSource object reference. Since the
> Reference does not match the driver factory is returning the null object.
>
>
> The sample code which is doing this inside driver factory is;
>
> Reference reference = (Reference)obj; //here it is getting
the
> wrong value
>
>
if(reference.getClassName().equals("com.microsoft.jdbcx.sqlserver.SQLServerD
ataS
> ource))
> {
> //create new SQLServerDataSource object;
> loadDataSourceAttributes(reference, newdatasourceobject);
> }
> return basedatasource;
>
> since the above if condition fails the you are recieving a null object.
>
> This behaviour is implemented based on the java spec.
> Look for 4th point in the java class doc javax.naming.spi.ObjectFactory
> (4. If obj is of any other type, the behavior of getObjectInstance() is
> determined by the context factory implementation)
>
> So if the tomcat context send the driverName value to the obj parameter
you
> can get the datasource from the context.
>
> Other approach is to write a class which creates the datasource and bind
it to
> the tomcat context and load this calss when server starts. I used this
approach
> and able to bind datasource to tomcat context.
>
> I am attaching the sample code which i used to bind datasource. Please
have a
> look into that class.
>
>
> This is my view on the tomcat datasource. Any ideas and information is
greately
> appriciated.