您好:
我用EXLIPSE +TOMCAT 7 ,想要用JNDI 與JSTL 的<SQL >TAG,實作如下:
目前用連線字串,但 用JNDI 就有問題.
請教 這如何解決呢?
謝謝!
我的步驟如下:
C:\xampp\tomcat\conf\server.xml
<GlobalNamingResources>
<Resource name="jdbc/MSSQL" type="javax.sql.DataSource" description="MSSQL" username="sa" password="1234"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://192.168.102.115:1433;instanceName=ptdb;DatabaseName=erp" auth="Container"/>
<GlobalNamingResources>
接著:
C:\xampp\tomcat\conf\context.xml
<Context>
<ResourceLink name="jdbc/MSSQLX" global="jdbc/MSSQL" type="javax.sql.DataSource" />
</Context>
接著:JSP中
從jndi名稱空間中獲得一個資料源。<br>
<sql:setDataSource
var="example3"
dataSource="jdbc/MSSQLX"
/>
<sql:query var="query3" dataSource="${example3}" >
select * from message
</sql:query>
這樣就出錯了。
org.apache.jasper.JasperException: An exception occurred processing JSP page /ch12/sql_datasource.jsp at line 64
61: </table>
62: <hr>
63:
64: <sql:query var="query3" dataSource="${example3}" >
65: select * from message
66: </sql:query>
67:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/MSSQLX"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
org.apache.jsp.ch12.sql_005fdatasource_jsp._jspService(sql_005fdatasource_jsp.java:144)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/MSSQLX"
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
org.apache.jsp.ch12.sql_005fdatasource_jsp._jspx_meth_sql_005fquery_005f2(sql_005fdatasource_jsp.java:507)
org.apache.jsp.ch12.sql_005fdatasource_jsp._jspService(sql_005fdatasource_jsp.java:132)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.53 logs.
------解决思路----------------------
web.xml
<resource-ref>
<res-ref-name>jdbc/xxx_cp</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
https://community.oracle.com/thread/723115
这个有用不...
话说你在做的是哪本书的例子啊?我也想看看
貌似从来没用过直接交给tomcat这样的数据源,jstl也巨少用