Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me public class Booking { protected static final String URL = jdbc:derby://localhost:1527/FlightSchedulerDBsfs5208; private static final String USERNAME = java; private static final

Can someone help me

image text in transcribed

image text in transcribed

public class Booking { protected static final String URL = "jdbc:derby://localhost:1527/FlightSchedulerDBsfs5208"; private static final String USERNAME = "java"; private static final String PASSWORD = "java"; private String flight; private Date date; private WaitList waitlist = new WaitList(); private int seatsBooked;

/** * */ protected static Connection connection; // manages connection private PreparedStatement selectAllPeople; private PreparedStatement selectPeopleByLastName; private PreparedStatement insertNewPerson; private PreparedStatement insertBookings; private PreparedStatement insertBooking; private PreparedStatement getFlightSeats;

public Booking() { super(); try { if(!isTableExisting()) { System.out.println("here"); createTable(); System.out.println("there"); } connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); getFlightSeats = connection.prepareStatement("select count(flight) from Bookings where flight = ? and date = ?"); selectAllPeople = connection.prepareStatement("SELECT * FROM Bookings where flight = ? and date = ?"); selectPeopleByLastName = connection.prepareStatement("SELECT * FROM Flights WHERE Name = ?"); insertNewPerson = connection.prepareStatement("INSERT INTO Flights " +"(flightId,Name,numSeats) " + "VALUES (?, ?, ?)"); insertBookings = connection.prepareStatement("INSERT INTO Bookings " +"(flightId, dayId, customerId) " + "VALUES (?, ?,?)"); insertBooking = connection.prepareStatement("INSERT INTO Bookings " +"(Name,Flight,Date) " + "VALUES (?,?,?)");

} catch (SQLException sqlException) { System.out.println("hello there"); sqlException.printStackTrace(); System.exit(1); } } private static boolean isTableExisting() { try { PreparedStatement s = connection.prepareStatement( "SELECT * FROM Bookings"); s.execute(); return true; } catch (SQLException ex) { return false; } } private void createTable() throws SQLException { PreparedStatement create = connection.prepareStatement( "CREATE TABLE Bookings(" + "bookingId INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1), " + "name VARCHAR(20), " + "flight VARCHAR(20) " + "date DATE " + "PRIMARY KEY(bookingId))"); create.execute(); }

run Exception in thread "main" java. lang .NullPointerException at flightschedulers fs5208. Booking. isTableExisting (Booking ava:76) at flightschedulers fs5208. Booking kinit (Booking ava: 52 at flight schedulersfs5208. FlightSchedulersfs5208.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

7. What traps should she avoid?

Answered: 1 week ago

Question

5. What decision-making model would you advocate to this person?

Answered: 1 week ago

Question

6. What data will she need?

Answered: 1 week ago