Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Open up your MySQL database interface using the method of your choice. 2 . Create a database called dblab, it will contain one

1. Open up your MySQL database interface using the method of your choice.
2. Create a database called dblab, it will contain one table called students (Fields
are id (varchar 20, and primary key) and name (varchar 50)).
3. Create a new project entitled DatabaseConnection.
4. You may download the mysql-connector-java.jar from the Installer Resources
folder in Google Drive. You can access it through the Google Classroom
5. Import the downloaded jar into your project.
6. Create a new package called factories.
7. Create a new class called DBConnectorFactory inside the factories package.
8. Inside the DBConnectorFactory create a private static attribute of type
java.sql.Connection (set it equal to null) and a public static method called
getDatabaseConnection with a return type of java.sql.Connection and it will
accept no parameters.
9. Complete the getDatabaseConnection method by first checking if the Connection
attribute is null, if it is, then connect to the database; if the connection was not
null then just return the connection.
10. Create a new package called models.
11. Create a new class called Student inside the models package, with a private
attribute of type java.sql.Connection.
12. Create a default constructor for the Student class. Inside the constructor use the
DBConnectorFactory to get a database connection and store it in your attribute.
13. Create four public methods inside the Student class:
a. void create(String id, String name)
b. void readAll()
c. void update(String id, String name)
d. void delete(String id)
14. Inside the create method use the parameters to build a SQL query that inserts a
new student into the database and executes the query.
15. Inside the readAll method read all students from the database and print it to the
screen.
16. Inside the update method use the parameters to build an SQL query that updates
the students name based on their id and executes the query.
17. Inside the delete method use the id parameter to build an SQL query that deletes
a student based on the id and executes the query.
18. Create a main package.
19. Create a driver class inside the main package with a main method. Inside the
main method instantiate your Student class and call the public methods in the
following order: create, readAll, update, readAll, delete, readAll. NB You will
need to use the Scanner class to accept user input for student creation, update
and delete. Only update and delete a user that you know exists.
20. implement the gui in the code for enter students name, Id, and methods in the
following order: create, readAll, update, readAll, delete, readAll.
21. Run your application.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

u = Umax 1 - n with: Umax = n+1 (- n+1 n 1 1. Apn 2 KL. n+1 a n

Answered: 1 week ago

Question

explain what is meant by redundancy

Answered: 1 week ago