- Copy your DB2 JDBC driver files(db2jcc4.jar and db2jcc_license_cu.jar) to glassfish/lib direcotry.
- Setup a singleton EJB to define your DataSourceDefinition:
- Add the JNDI reference in your persistence.xml:
- In your Rest resource file
@DataSourceDefinition( className="com.ibm.db2.jcc.DB2DataSource", serverName="host_name", name="java:global/jdbc/APP", databaseName="database_name", portNumber=db_port, user="username", password="passowrd", properties={"driverType=4"} ) @Singleton public class DataSourceConfiguration { }
java:global/jdbc/APP
... @PersistenceContext EntityManager em; ... @GET @Produces("application/xml") public String getXml() { Query q = em.createQuery("select c from Customer c"); Listcustomers = q.getResultList(); return " " + customers.get(1).getId() + " "; }
There are a few catches I ran into:
- Error:
Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError
You need to add the vendor specific properties: driverType=4 to force it use type 4 JDBC driver.
No comments:
Post a Comment