Question: Open up your MySQL database interface using the method of your choice. 2 . Create a database called dblab, it will contain one table called
Open up your MySQL database interface using the method of your choice.
Create a database called dblab, it will contain one table called students
Fields
are id
varchar
and primary key
and name
varchar
Create a new project entitled DatabaseConnection.
You may download the mysql
connector
java.jar from the Installer Resources
folder in Google Drive. You can access it through the Google Classroom
Import the downloaded jar into your project.
Create a new package called factories.
Create a new class called DBConnectorFactory inside the factories package.
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.
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.
Create a new package called models.
Create a new class called Student inside the models package, with a private
attribute of type java.sql
Connection.
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.
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
Inside the create method use the parameters to build a SQL query that inserts a
new student into the database and executes the query.
Inside the readAll method read all students from the database and print it to the
screen.
Inside the update method use the parameters to build an SQL query that updates
the student
s name based on their id and executes the query.
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.
Create a main package.
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.
implement GUI methods for the
following order: create, readAll, update, readAll, delete, readAll
Run your application.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
