[ad_1]
I am trying to Create a SQL Booking by using variables like adults booked customerid children booked ,check-in and check-out date however when i try to input date into the java code to create a booking i keep getting the error error: incompatible types: int cannot be converted to Date book.CreateBooking(5 , 1 , 2 , 2022-04-21 , 2022-04-24 ); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error
This a school assignment due in a day, and i cant get over this createbooking section
My Code
import java.sql.* ;
import java.util.Date;
public class Booking
{
private int iBookingID;
private int iCustomerID;
private int iAdultsBooked;
private int iChildrenBooked;
private Date szCheckIn;
private Date szCheckOut;
private int iNumRows ;
// DB materials.
private String sql ;
private String sz ;
private Statement sqlStatement = null ;
private ResultSet resultSet = null ;
private Session dbSession ;
public Booking()
{
reset() ;
this.dbSession = new Session() ;
dbSession.connect();
if ( dbSession.isConnected() == false )
{
System.err.println( this.getClass().getName() + ":: failed to connect to DB for table." ) ;
}
countRows() ;
return ;
}
protected void reset()
{
iNumRows = -1 ; // to spot the difference between empty table & no methods run.
sz = null ;
sql = null ;
sqlStatement = null ;
resultSet = null ;
return ;
}
// Setters
public void setAdultsBooked (int iAdultsBooked)
{
this.iAdultsBooked = iAdultsBooked ;
}
public void setChildrenBooked (int iChildrenBooked)
{
this.iChildrenBooked = iChildrenBooked ;
}
public void setCheckIn (Date szCheckIn)
{
this.szCheckIn = szCheckIn ;
}
public void setCheckOut (Date szCheckOut)
{
this.szCheckOut = szCheckOut ;
}
public void setCustomerID (int iCustomerID)
{
this.iCustomerID = iCustomerID ;
}
public void setBookingID (int iBookingID)
{
this.iBookingID = iBookingID ;
}
// Getters
public int getAdultsBooked ()
{
return this.iAdultsBooked ;
}
public int getChildrenBooked ()
{
return this.iChildrenBooked ;
}
public Date getCheckOut ()
{
return this.szCheckOut ;
}
public Date getCheckIn ()
{
return this.szCheckIn ;
}
public int getCustomerID ()
{
return this.iCustomerID ;
}
public int getBookingID ()
{
return this.iBookingID ;
}
//Create Booking
public boolean CreateBooking(int iCustomerID, int iAdultsBooked, int iChildrenBooked, Date szCheckOut, Date szCheckIn )
{
boolean bRC = false ;
clearAttributes() ;
this.setCustomerID(iCustomerID);
this.setAdultsBooked(iAdultsBooked);
this.setChildrenBooked(iChildrenBooked);
this.setCheckIn(szCheckIn);
this.setCheckOut(szCheckOut);
bRC = this.CreateBooking() ;
return ( bRC ) ;
}
public boolean CreateBooking()
{
boolean bRC = false ;
int iRC ;
try
{
System.err.println( this.getClass().getName() + ":: DB connected := " + dbSession.isConnected() ) ;
sql = "INSERT INTO Bookings( "
+ " CustomerID"
+ ", AdultsBooked"
+ ", ChildrenBooked"
+ ", Check_In"
+ ", Check_Out"
+ " ) "
+ " VALUES( "
+ " \"" + this.getCustomerID() + "\""
+ ", \"" + this.getAdultsBooked() + "\""
+ ", \"" + this.getChildrenBooked() + "\""
+ ", \"" + this.getCheckIn() + "\""
+ ", \"" + this.getCheckOut() + "\""
+ " ) ; " ;
sqlStatement = dbSession.getConnection().createStatement() ;
iRC = sqlStatement.executeUpdate( sql ) ;
return ( bRC ) ;
}
public void display()
{
sql = "SELECT * FROM Bookings;" ;
sz = "::display()\n" ;
sz = sz + "\n\tBookingID := " + getBookingID() ;
sz = sz + "\n\tCustomerID := " + getCustomerID() ;
sz = sz + "\n\tAdultsBooked := " + getAdultsBooked() ;
sz = sz + "\n\tChildrenBooked := " + getChildrenBooked() ;
sz = sz + "\n\tCheck_Out := " + getCheckOut() ;
sz = sz + "\n\tCheck_In := " + getCheckIn() ;
System.out.println( this.getClass().getName() + sz ) ;
return ;
}
//----------------------------------------------------------------------
// test rig
//----------------------------------------------------------------------
public static void main( String [] args )
{
Booking book = new Booking();
book.CreateBooking(5 , 1 , 2 , 2022-04-21 , 2022-04-24 );
book.display();
return;
}
[ad_2]