Programming

(JSP) DataSource invalid: "java.sql.SQLException: No suitable driver"

steloflute 2021. 9. 13. 23:42

DataSource invalid: "java.sql.SQLException: No suitable driver" — oracle-tech

I think this is a classloader problem. JSTL uses a static method DataSourceUtil.getDataSource(Object, PageContext) to lookup de datasource. It throws a java.sql.Exception, not a NamingException.

Instead of: <sql:setDataSource dataSource="YourDS" var="conn" scope="application" />

use: <% javax.naming.Context ctx = new javax.naming.InitialContext(); javax.sql.DataSource dataSource = (javax.sql.DataSource) ctx.lookup("java:YourDS"); pageContext.setAttribute("conn",dataSource); %>

 

이후에, JSTL sql 태그에서 dataSource를 ${conn}으로 잡으면 된다.

 

Instead of: <sql:setDataSource dataSource="YourDS" var="conn" scope="application" /> use: <% javax.naming.Context ctx = new javax.naming.InitialContext(); javax.sql.DataSource dataSource = (javax.sql.DataSource) ctx.lookup("java:YourDS"); pageContext.setAttribute("conn",dataSource); %>