DBMS Exp-14
DBMS Exp-14
SOLUTION:
1. Software Requirements:
Java Development Kit (JDK): Version 8 or later
Database: XAMPP Server
JDBC Driver: Corresponding JDBC driver for the selected database (e.g.,
MySQL Connector/J for MySQL) //mysql-connector-j-9.1.0.jar
Database Credentials: Database URL, username, and password
2. Functional Requirements:
Establish a connection to the database using JDBC
Execute a simple SQL query (e.g., retrieving data from a table)
Display query results in the console
Handle exceptions properly (e.g., SQLExceptions)
Ensure proper resource management (closing connections)
Source code
Page 1
String username = "root"; // Database username
String password = ""; // Database password (leave empty if none)
try {
// Load the MySQL JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
Page 3