I'm working on a project where I have an SQL table with just one column that contains strings of holiday names. I am trying to get all of the holiday names in that column into an arraylist using a prepared statement (I have to use a prepared statement). However, I just am lost at to what I am doing wrong. Thanks! Feel free to ask for any clarifications. (FYI the database url is correct and the column name i wish to access is holidays
public class Holidays
{
private ArrayList<String> holidays;
final String DATABASE_URL = "jdbc:derby://localhost:1527/MovieAgent";
final String SELECT_QUERY = "SELECT HOLIDAYS FROM HOLIDAY";
final String USERNAME = "james";
final String PASSWORD = "am";
private Connection connection;
private Statement statement;
private PreparedStatement selectHolidays;
private PreparedStatement insertHoliday;
private int rowCount;
public Holidays()
{
String holidayName;
holidays = new ArrayList<>();
try{
connection = DriverManager.getConnection(DATABASE_URL, "al", "al");
statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
selectHolidays = connection.prepareStatement(SELECT_QUERY);
ResultSet resultSet;
resultSet = selectHolidays.executeQuery();
while(resultSet.next())
{
holidayName = resultSet.getString(1);
holidays.add(holidayName);
}
}catch(SQLException sqlException)
{
sqlException.printStackTrace();
System.exit(1);
}
}
Edit: Sorry I left out that it's simply not working. The values are just not appearing the arraylist. The arraylist (holidays) appears to be empty.