This assignment aims to introduce students to JDBC (Java Database Connectivity) and guide them through connecting to a MySQL database and executing queries.
-
Download and install MySQL: Install MySQL on your machine if you haven't already. You can download it here.
-
Create a Database: Using MySQL Workbench or any MySQL client, create a new database named
university. -
Create a Table: Within the
universitydatabase, create a table namedstudentswith the following columns:id(INT, PRIMARY KEY, AUTO_INCREMENT)name(VARCHAR)age(INT)
Write a Java program that connects to the MySQL database and performs the following operations:
-
Connect to the Database:
- Use JDBC to establish a connection to the MySQL database.
-
Insert Data:
- Insert at least two records into the
studentstable.
- Insert at least two records into the
-
Retrieve Data:
- Retrieve and print all records from the
studentstable.
- Retrieve and print all records from the
-
Update Data:
- Update the age of one student.
-
Delete Data:
- Delete one student from the table.
Submit the Java source code file along with a screenshot of the table you created using MySQL Shell in the same way you submitted your last assignment.
- Use the JDBC documentation (Oracle JDBC API) as a reference guide.
- Ensure you have the MySQL Connector/J library in your project. You can download it here.
- If you face any issues, you can contact your technical executives and peers in the community!