'SQL, How do i display all info after entering a start date

this is my user interface where i would prompt them to enter a starting date

public void viewAllTicket() throws Exception {

        String ticketDate;
        int dd = 0, mm = 0, yy = 0;
        boolean dateDNE = true;
        String result[] = null;
        int transactionId = 0;
        System.out.println("Enter start date: ");
        ticketDate=scan.nextLine();
        
        result = db.retrieveAllRecords();
        System.out.println();
        System.out.printf("%-10s %10s %10s %20s %10s\n", "Ticket Date |", "Transaction Id |", "Number of Tickets |",
                "Member Phone Number |", "Total Price");
        for (int cnt = 0; cnt < 80; cnt++)
            System.out.print("=");
        System.out.println();
        for (String temp : result)
            System.out.println(temp);
        System.out.println();

    }
}

this is in my DBController where it displays all the records

public String[] retrieveAllRecords() throws Exception {
        String arr[] = null;
        int count = 0;

        String sql5 = "SELECT * FROM `themepark`";

        ResultSet result = stmt.executeQuery(sql5);

        if (result.last()) {
            count = result.getRow();
            arr = new String[count];
            result.beforeFirst();
        }
        count = 0;
        while (result.next()) {
            String tempDate = result.getString("Ticket_Date");
            int tempId = result.getInt("Transaction_Id");
            int tempTicket = result.getInt("Number_of_Tickets");
            int tempPhoneNumber = result.getInt("Member_Phone_Number");
            int tempTotalPrice = result.getInt("Total_Price");

            String temp = String.format("%-10s %10d %18d %22d %15d", tempDate, tempId, tempTicket, tempPhoneNumber,
                    tempTotalPrice);
            arr[count] = temp;
            count++;
        }
        return arr;
    }
public static void main(String[] args) throws Exception {
        DBController db = new DBController();
        String ticketDate = null;
        String temp[] = db.retrieveAllRecords();
        for (String t : temp)
            System.out.println(t);

    }
}

so currently with these 2 classes, i would be displaying all the ticket transaction info.

My question is, if i were to prompt user to enter a start date of a ticket, how/what do i do to only display ticket transaction info from the start date onwards

For example, if these are all the ticket dates of the transactions, 14th feb,14th feb,14th feb,15th feb,15th feb,16th feb,17th feb

fter prompting user for start date, Enter start date: 15th feb

Output would be: 15th feb,15th feb,16th feb,17th feb

I appreciate any help given



Solution 1:[1]

You would parse the user’s input as a LocalDate object.

You would define the date column in your database table to be of a data type akin to the SQL-standard type DATE.

You would add a WHERE clause to your SQL to search for date values after the user-specified date.

You would rewrite your SQL statement to be a prepared statement. Then pass the LocalDate in a call to setObject.

When retrieving data you would use getObject on your ResultSet to obtain a LocalDate object.

All of these topics have been covered many times already on Stack Overflow. Search to learn more.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Basil Bourque