DBMS Exp-15
DBMS Exp-15
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
import java.sql.*;
import java.util.Scanner;
Page 1
String username = "root"; // Replace with your database username
String password = ""; // Replace with your database password
Page 2
// Close the connection
connection.close();
} catch (Exception e) {
// Handle exceptions
e.printStackTrace();
}
}
while (resultSet.next()) {
int Stuid = resultSet.getInt("Stuid");
String Stuname = resultSet.getString("Stuname"); // Adjust column
name if different
Page 3
Page 4