Answered step by step
Verified Expert Solution
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
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 mysqlconnectorjava.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.sqlConnection set it equal to null and a public static method called
getDatabaseConnection with a return type of java.sqlConnection 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.sqlConnection.
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 createString id String name
b void readAll
c void updateString id String name
d void deleteString 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 students 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 the gui in the code for enter students name, Id and methods in the
following order: create, readAll, update, readAll, delete, readAll.
Run your application.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started