Java Springboot With FireBird

 Java Springboot With FireBird is a development stack for web or desktop based apps.

We will use Java language with springboot framework to build a basic restful API. Our purpose is to setup the environment and access data from database using our Browser. We require following software:

1.   Intelli J studio

2.   Jdk (latest)

3.   Firebird (latest)

 Step 1: Download and Install Firebird database (it comes with Command line SQL executor) as shown below:

Step 2:  Execute and test sample SQL script to verify connectivity with local system Firebird instance.

Step 3: Download JBird driver for connectivity with Java instance.

 Step 4: Download and install IntelliJ idea studio.

Step 5: Create Intelli J New Project (Spring Initializer)

Step 6: Set Datasource using previously downloaded JBird.

Step 7: Coding Starts:

·        Update POM file for all dependencies (you need internet access on development machine for this)

·        Configure data source from ‘application.properties’

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:firebirdsql://localhost:3050/C:/Program Files/Firebird/Firebird_3_0/examples/empbuild/employee.fdb
spring.datasource.hikari.data-source-properties.charSet=utf-8
spring.datasource.username=sysdba
spring.datasource.driverClassName=org.firebirdsql.jdbc.FBDriver
spring.datasource.password=masterkey
spring.jpa.show-sql= true
spring.jpa.properties.hibernate.format_sql=true

·        Create Entity, Repository and Restful Controller

-         Controller is as below:

@RestController
@RequestMapping("/API")
public class APIController {
    @Autowired
    IEmployeeRepository iEmployeeRepository;
   
@RequestMapping("/")     public String helloWorld(){         return "Hello World from Spring Boot";     }
   
@RequestMapping("/allData")     public List<EmployeeEntity> GetAllData(){         return iEmployeeRepository.findAll() ;     }     //paramFirst : this argument takes Number of data Rows to be returned
   
@RequestMapping("/FilteredData")     public List<EmployeeEntity> GetAllDataOnly(@RequestParam Integer paramFirst){         return iEmployeeRepository.findData(paramFirst) ;     } }

-         Repository is as below:

public interface IEmployeeRepository  extends JpaRepository<EmployeeEntity, Integer> {
        List<EmployeeEntity> findAll( );
        //  Using Native Query to find N number of rows
        @Query(value = "SELECT first ?1 EMP_NO,FIRST_NAME,LAST_NAME,PHONE_EXT,HIRE_DATE,DEPT_NO, JOB_CODE, JOB_GRADE,JOB_COUNTRY,SALARY,FULL_NAME FROM EMPLOYEE" , nativeQuery = true)
        List<EmployeeEntity> findData(Integer paramFirst);
}

-         Entity is as below:

@Entity
@Table
(name = "EMPLOYEE", schema = "", catalog = "")
public class EmployeeEntity {
   
@Id
    @GeneratedValue
(strategy = GenerationType.IDENTITY)
   
private Integer empNo;
    private
String firstName;
    private
String lastName;
    private
String phoneExt;
  
@GeneratedValue(strategy = GenerationType.IDENTITY)
   
@javax.persistence.Id
    @Column
(name = "EMP_NO")
   
public Integer getEmpNo() {
       
return empNo;
   
}
   
public void setEmpNo(Integer empNo) {
       
this.empNo = empNo;
   
}
   
@Basic
    @Column
(name = "FIRST_NAME")
   
public String getFirstName() {
      
return firstName;
   
}
   
public void setFirstName(String firstName) {
       
this.firstName = firstName;
   
}
   
@Basic
    @Column
(name = "LAST_NAME")
   
public String getLastName() {
       
return lastName;
   
}
   
public void setLastName(String lastName) {
       
this.lastName = lastName;
   
}

·        Access API from browser and check results.

Results:

Data is successfully accessed from the Firebird Data table. You can use any database, only requirement is to have particular sql or no sql Driver. For any queries you can write to me.

Fiver: https://www.fiverr.com/jazzi1991?public_mode=true

Email: baseer.softengr@gmail.com

Comments

Popular posts from this blog

PYTHON Data Science

Cisco Contact Center - Customize Reports & Queries in CUIC - UCCX