How to connect to external database from Liferay 6.2

How to connect to External DB in Liferay ?

1. Create a database with the following name:

anotherdatabase

2. Create a table as shown below:
 CREATE TABLE `anotherdatabase`.`Employee2` ( `userId` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `FirstName` VARCHAR(45) NOT NULL DEFAULT '', `LastName` VARCHAR(45) NOT NULL DEFAULT '', `Gender` VARCHAR(45) NOT NULL DEFAULT '', `DateOfBirth` VARCHAR(45) NOT NULL DEFAULT '', `Email` VARCHAR(45) NOT NULL DEFAULT '', `Password` VARCHAR(45) NOT NULL DEFAULT '', `ConfirmPassword` VARCHAR(45) NOT NULL DEFAULT '', `MobileNo` VARCHAR(45) NOT NULL DEFAULT '', PRIMARY KEY(`userId`) ) ENGINE = InnoDB;
 

3. Create Folder with the name META-INF folder under docroot/WEB-INF/src.

4. Create a file with the name ext-spring.xml inside the META-INF folder.

add the below code in the ext-spring.xml file:
 
 

       
              
       
       
              
       
       
                     
       
              
       
       
                                                 
                           
                     
                     

       

                                                 
                           
                           
                           
                     
                     

 

5. Create service.xml for your custom portlet and then add the data source object which is added in the ext-spring.xml file.

 vidyayugg
 a
 
  
  
  
  
  
  
  
  
  
 
 
6. Add the below code to connect to the external database.
jdbc configuration jdbc.anotherdbconfig.driverClassName=com.mysql.jdbc.Driver 
jdbc.anotherdbconfig.username=root 
jdbc.anotherdbconfig.password=
jdbc.anotherdbconfig.url=jdbc:mysql://localhost:3306/anotherdatabase?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false 

7. Perform ant-build service and then deploy,next use the classes to store the data in the external database.

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.