ABC Corp is planning to maintain all petty cash payment information to employees in a database. You are helping the finance department of ABC Corp implement it. Since ABC Corp is expanding its operations, adding new employees to the system is a common requirement due to new hires.
Your task is to add the provided new employee details to the Employee table of the database and return the value of the auto-generated employee_id column without issuing another query to the database to find it. If an error occurs during the execution, -1 should be returned.
Use the provided H2 database for this problem.
The sample database file is
gofigure.mv.db, and the database name isgofigure. It is given within thedbfolder.
The following tables are already in the sample H2 database with some sample data. The column names and data types are below.
Table name : Employee
| Columns: | type |
|---|---|
employee_id | integer, auto-incremented primary key |
name | string |
city | string |
department | string |
age | integer |
Table Name: Payment
| Columns: | type |
|---|---|
payment_id | integer, auto-incremented primary key |
date | date |
amount | decimal |
employee_id | integer |
reason | string |
gofigure.mv.db. Use the JDBC URL as jdbc:h2:file:/path/to/db/filerootrootdb folder to validate queries and the Ballerina samplebal test, and it will run tests against the given sample DB.Input : dbFilePath: "./db/gofigure", name : “John Doe”, city: “Omaha”, department : “Sales”, age: 24
Output : 4
Input : dbFilePath: "./db/invalidDB", name : “John", city: "Colombo", department : "HR", age: 25
Output : -1
ABC Corp is planning to maintain all petty cash payment information to employees in a database. You are helping the finance department of ABC Corp implement it. Since ABC Corp is expanding its operations, adding new employees to the system is a common requirement due to new hires.
Your task is to add the provided new employee details to the Employee table of the database and return the value of the auto-generated employee_id column without issuing another query to the database to find it. If an error occurs during the execution, -1 should be returned.
Use the provided H2 database for this problem.
The sample database file is
gofigure.mv.db, and the database name isgofigure. It is given within thedbfolder.
The following tables are already in the sample H2 database with some sample data. The column names and data types are below.
Table name : Employee
| Columns: | type |
|---|---|
employee_id | integer, auto-incremented primary key |
name | string |
city | string |
department | string |
age | integer |
Table Name: Payment
| Columns: | type |
|---|---|
payment_id | integer, auto-incremented primary key |
date | date |
amount | decimal |
employee_id | integer |
reason | string |
gofigure.mv.db. Use the JDBC URL as jdbc:h2:file:/path/to/db/filerootrootdb folder to validate queries and the Ballerina samplebal test, and it will run tests against the given sample DB.Input : dbFilePath: "./db/gofigure", name : “John Doe”, city: “Omaha”, department : “Sales”, age: 24
Output : 4
Input : dbFilePath: "./db/invalidDB", name : “John", city: "Colombo", department : "HR", age: 25
Output : -1