Monday, March 12, 2012

MS SQL jdbc driver problem in Connection pool in TOMCAT 5

I have problem in creating connection pool with MS SQL Server JDBC
Driver. I use Apache 2.0.49, Tomcat 5.0.19, windows 2000 server, MS
SQL server 2000 + sp4
My configuration is as following. The error occurs at
envCtx.lookup("jdbc/dbname");
1) I copy the three jar files to \common\lib in %catalina_home% from
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC
2) MY webapps/ROOT/web-inf/web.xml is:
...
<resource-ref>
<description> JDBC Driver:
com.microsoft.jdbc.sqlserver.SQLServerDriver</description>
<res-ref-name>jdbc/dbname</res-ref-name>
<res-type>com.microsoft.jdbcx.sqlserver.SQLServerDataSo urce</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
3) my JSP file is in /ROOT/zuo, it contains code:
<%@. page import="java.sql.*" %>
<%@. page import="java.lang.reflect.*" %>
<%@. page import="java.io.*" %>
<%@. page import="javax.naming.*" %>
.....
<%....
envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (ConnectionPoolDataSource ) envCtx.lookup("jdbc/dbname");
if (ds != null){
if(ds instanceof com.microsoft.jdbcx.sqlserver.SQLServerDataSource) {
SQLServerDataSource temp =
(com.microsoft.jdbcx.sqlserver.SQLServerDataSource )ds;
con = temp.getPooledConnection("dzuo","dzuo").getConnect ion();
...%>
4) I add text in apache2/conf/server.xml :
<GlobalNamingResources>
.....
<Resource name="jdbc/dbname" auth="container"
type="com.microsoft.jdbcx.sqlserver.SQLServerDataS ource" />
<ResourceParams name="jdbc/dbname">
<parameter>
<name>factory</name>
<value>com.microsoft.jdbcx.sqlserver.SQLServerData SourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbcx.sqlserver.SQLServerData Source</value>
</parameter>
<parameter>
<name>driverName</name>
<value>SQLServer</value>
</parameter>
<parameter>
<name>description</name>
<value>SQL Server DataSource</value></parameter>
<parameter>
<name>serverName</name><value>"serverNmae"</value>
</parameter>
<parameter>
<name>portNumber</name><value>1433</value>
</parameter>
<parameter><name>user</name><value>"dzuo"</value></parameter>
<parameter><name>password</name><value>"dzuo"</value></parameter>
</ResourceParams>
(... other resources ...)
</GlobalNamingResources>
.....
</Host>
</Engine>
</Service>
</Server>
Please forward instruction, or any suggestion. Thanks a lot.
Did you had any luck. I am trying to do the same thing under tomcat. So far no luck with connection pooling.
|||use com.microsoft.jdbc.sqlserver.SQLServerDriver instead of com.microsoft.jdbcx.sqlserver.SQLServerDataSource as the jdbc driver.
I use the admin UI to config
step 1: create context;
step 2: create datasource, like following:
JNDI Name: jdbc/mnr
Data Source URL: jdbc:microsoft:sqlserver://mnrserver:1433;
JDBC Driver Class: com.microsoft.jdbc.sqlserver.SQLServerDriver
User Name: mnr
Password: xxxx
Max. Active Connections: 4
Max. Idle Connections: 2
Max. Wait for Connection: 5000
Validation Query: select * from MNR_Estm
step 3: jsp
<%@.page import="java.sql.*"%>
<%@.page import="javax.sql.*"%>
<%@.page import="javax.naming.*"%>
<%
DataSource ds = null;
InitialContext initContext = new javax.naming.InitialContext();
out.print("Getting datasource(jdbc/css)... ");
ds = (javax.sql.DataSource)initContext.lookup("java:com p/env/jdbc/mnr");
out.println("successfully");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery(" select * from MNR_Estm");
while(rst.next()){
out.println(rst.getString("Estno"));
}
conn.close();
%>
step 4: access http://127.0.0.1:9000/quartz/scripts/edi/b.jsp
It's ok.
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.

No comments:

Post a Comment