datasource - how to used data source declared in tomee.xml in java class -


hi configure data source in tomee.xml file , web.xml file.this work fine when executing project implmented test case need used when used there giving exception javax.naming.noinitialcontextexception: need specify class name in environment or system property, or applet parameter, or in application resource file: java.naming.factory.initial

this tomee.xml file

     <?xml version="1.0" encoding="utf-8"?>      <tomee>        <resource id="jdbc/mydb" type="datasource">              jdbcdriver com.mysql.jdbc.driver                  jdbcurl jdbc:mysql://localhost:3306/test              username root              password root                  jtamanaged false                 initialsize 50               maxactive 100              maxidle 3        </resource>      </tomee> 

this code working fine in servlet when writing in java class giving exception java class accessing

     context initcontext = new initialcontext();      context envcontext  = (context)initcontext.lookup("java:/comp/env");      datasource ds = (datasource)envcontext.lookup("jdbc/mydb");      con = ds.getconnection(); 

you visits link give solution loocking. http://poolofjava.blogspot.in/2013/08/how-to-bind-datasource-with.html


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -