1. Under the project source folder, create the persistent. xml file.
Project name
-- | SRC
-- | Persistence. xml
2. Compile the persistent. xml file in the following format.
<? XML version = "1.0" encoding = "UTF-8"?> <Persistence version = "1.0" xmlns = "http://java.sun.com/xml/ns/persistence" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name = "cici_persistence_unit" transaction-type = "resource_local"> <provider> Org. eclipse. persistence. JPA. persistenceprovider </provider> <class> COM. cici. CRM. migration. model. CRM. crmcardinstance </class> <class> COM. cici. CRM. migration. model. CRM. crmapplicationinstance </class> <Properties> <property name = "eclipselink. JDBC. native-SQL "value =" true "/> <property name =" eclipselink. JDBC. batch-writing "value =" JDBC "/> <property name =" eclipselink. logging. level "value =" off "/> <property name =" eclipselink.tar get-Database "value =" oracle "/> <property name =" eclipselink. JDBC. URL "value =" JDBC: oracle: thin: @ localhost: 1521: cicidb "/> <property name =" eclipselink. JDBC. driver "value =" oracle. JDBC. driver. oracledriver "/> <property name =" eclipselink. JDBC. user "value =" admcici "/> <property name =" eclipselink. JDBC. password "value =" admcici "/> <property name =" eclipselink. DDL-generation "value =" NONE "/> </Properties> </persistence-unit> </persistence>
3. Create a map containing dB connection Parameters
Map <string, string> properties = new hashmap <string, string> (); properties. put ("Your selink. JDBC. user ", configuration. getinstance (). getvalue (configuration. otam_database_username); properties. put
("Eclipselink. JDBC. Password", configuration. getinstance (). getvalue (configuration. otam_database_password ));
4. Create entitymanagerfactory
EntitymanagerfactoryRcafactory =Persistence. Createentitymanagerfactory (cici_persistence_unit, properties );
5. Create entitymanager
EntitymanagerEntitymanager = rcafactory. createentitymanager ();
6. Create entitytransaction and enable connection
Entitymanager. GetTransaction(). Begin ();
7. Create a query and execute an SQL statement
QueryQuery = entitymanager. createnamedquery (SQL );
Query.exe cuteupdate ();
8. Submit a transaction
Entitymanager. gettransaction (). Commit ();
9 Close the connection
Entitymanger. Close ();
Cicifacloud. Close ();