Question: in java Q4 [15 points] Database . Using NetBeans, create a new database and call it DbFinal , and give it the username userfinal, and
in java
Q4 [15 points] Database.
- Using NetBeans, create a new database and call it DbFinal, and give it the username userfinal, and the password dbpassfinal.
- Implement a Java class called EmpDataBase, which has the following three methods:
1- public void createTable(). This method connects to the database DbFinal, and creates a new table called Employee in DbFinal. The table contains the fields:
- EmpId, Integer, not null, primary key.
- Name, VARCHAR(255)
- Salary, Integer
- Company, VARCHAR(255)
2- public void insertData(). This method connects to the database DbFinal, and inserts the following records into the Employee table:
112, Ahmed, 900, Microsoft
200, Muna, 700, IBM
422, Enas, 800, IBM
3- public void getData(). This method connects to the database DbFinal and retrieves each employee record that has the company name equal to IBM. Then, the method prints (using System.out.println) the EmpId and salary fields of each retrieved record.
Important note: Inside each of the above three methods, you must write all the necessary code to connect to the database, create and execute statements, and close the connection. You must also write the necessary try-catch blocks. In the catch blocks, call the printStackTrace() method.
4- Main method. This method creates and instantiates and object of type EmpDataBase, then calls the methods createTable(), insertData(), and getData().
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
