java - Create JNDI Connection for Ingres Database -
i have java project , i've been trying create jndi connection ingres database have been unsuccessful. i'm not sure if there specific ingres needs included after quite bit of research haven't been able things work.
in project have datasource info in web.xml file , context.xml
context.xml has following info
<context> <resource name="jdbc/mydb" auth="container" type="javax.sql.datasource" username="myuser" password="password" driverclassname="com.ingres.jdbc.ingresdriver" url="databaseurl" maxactive="8" maxidle="4" maxwait="100" /> </context>
my web.xml has following info
<web-app> <resource-ref> <description>project descrip</description> <res-ref-name>jdbc/mydb</res-ref-name> <res-type>javax.sql.datasource</res-type> <res-auth>container</res-auth> </resource-ref> </web-app>
in java code i'm trying connection using following 4 lines
context initcontext = new initialcontext(); context envcontext = (context) initcontent.lookup("java:comp/env"); datasource ds = (datasource) envcontext.lookup("jdbc/mydb"); return ds.getconnection();
after third line executed exception says: namingexception - cannot create resource instance
i have found dozens of posts same exception , have tried suggested solutions no luck. i'm using tomcat 7 server , have made sure include necessary ingres jar (iijdbc.jar) web-inf/lib folder , tomcat lib folder.
any or suggestions appreciated
i don't know ingres, if attempting make datasource similar jboss , db2 or mysql. noticed in web.xml define resource-ref, don't mention servlet parameters.
<servlet> <description>servlet description</description> <display-name>myservlet</display-name> <servlet-name>myservlet</servlet-name> <servlet-class>servlet.myservlet</servlet-class> <init-param> <param-name>mydb</param-name> <param-value>java:comp/env/jdbc/mydb</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
then need code in sevlet:
initialcontext initialcontext = new initialcontext(); datasource datasource = (datasource)initialcontext.lookup(this.getinitparameter("mydb"));
hope helps.
Comments
Post a Comment