I am getting the following error when I try to execute test2.jsp from tomcat.
SEVERE: Servlet.service() for
servlet jsp threw exception
javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.jsp.test2_jsp._jspService(test2_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Configuration:
Tomcat 6.0
Platform Windows XP (laptop)
I have edited the following configuration files:
1. ..\config\context.xml ADDED
<Resource name="jdbc/fsDB" auth="Container" type="Javax.sql.DataSource "
maxActive = "100" maxIdle = "30" maxWait = "5000"
username="user" password="psw"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://myserver:1433;databaseName=Stage;SelectMethod=cursor"
/>
2. ..\webapps\birt\WEB-INF\web.xml ADDED
<resource-ref>
<description>MS Sql Data Source</description>
<res-ref-name>jdbc/fsDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. ...\webapps\birt\META-INF\context.xml CREATED FOLDER AND FILE
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/fsDB" auth="Container" type="Javax.sql.DataSource "
maxActive = "100" maxIdle = "30" maxWait = "5000"
username="StageUser" password="St4g3Us3r"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://fs121:1433;databaseName=Stage;SelectMethod=cursor"
/>
</Context>
4 Wrote (stole from web) test2.jsp
%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<HTML>
<HEAD>
<TITLE>JSP example</TITLE>
</HEAD>
<BODY>
<h1>Hello,
test JNDI ! </h1>
<%
Context ctx = new InitialContext();
Context envctx = (Context) ctx.lookup("java:comp/env");
DataSource ds = (DataSource) envctx.lookup("jdbc/fsDB");
Connection conn=ds.getConnection();
Statement st=conn.createStatement();
String sql="select srvname from master.dbo.sysservers where srvid=0";
ResultSet rs=st.executeQuery(sql);
while(rs.next()) {
%>
Server:<%=rs.getString(1) %>
<br>
<%
}
%>
Here is just JNDI datasource SQL Server 2005 + tomcat example
<%
rs.close();
st.close();
conn.close();
%>
</BODY>
</HTML>
Any help would be appreciated. I have been fighting with this for several days. Internet appears to have multiple ways of doing this, but I could not get any specific method to work.
Thanks,