package task9;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class callableprocedures {
    // Database credentials and URL
    static final String JDBC_URL = "jdbc:mysql://localhost:3306/varshitha"; // Replace with your database name
    static final String JDBC_USER = "root"; // Replace with your MySQL username
    static final String JDBC_PASSWORD = "root"; // Replace with your MySQL password

    public static void main(String[] args) {
        // SQL query to call the stored procedure
        String callProcedureSQL = "{call selectGradeAStudents()}";

        try (Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
             CallableStatement callableStatement = connection.prepareCall(callProcedureSQL);
             ResultSet resultSet = callableStatement.executeQuery()) {

            System.out.println("Students with Grade A:");
            while (resultSet.next()) {
                // Assuming the Students table has columns: id, name, age, and grade
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                int age = resultSet.getInt("age");
                String grade = resultSet.getString("grade");
                
                System.out.printf("ID: %d, Name: %s, Age: %d, Grade: %s%n", id, name, age, grade);
            }

        } catch (SQLException e) {
            System.out.println("SQL Exception: " + e.getMessage());
        }
    }