-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooking.java
More file actions
72 lines (58 loc) · 1.75 KB
/
Copy pathBooking.java
File metadata and controls
72 lines (58 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package BusReservation;
import java.util.*;
import java.sql.*;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Booking {
String PassengerName;
static int BusNo;
static Date date;
Booking(Scanner sc)
{
System.out.println("Enter name of the Passenger: ");
PassengerName = sc.next();
System.out.println("Enter the bus number: ");
BusNo = sc.nextInt();
System.out.println("Enter the date dd-mm-yyyy: ");
String tempDate = sc.next();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
try {
date = sdf.parse(tempDate);
}
catch(ParseException e)
{
e.printStackTrace();
}
}
public static boolean isAvailable() throws SQLException
{
int capacity = Bus.getCapacity(BusNo);
Connection con = DBConnection.getConnection();
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
String Q = "select count(*) from booking where bus_no = ? and travel_date = ? ";
PreparedStatement pdt = con.prepareStatement(Q);
pdt.setInt(1,BusNo);
pdt.setDate(2,sqlDate);
ResultSet rs = pdt.executeQuery();
rs.next();
int booked = rs.getInt(1);
if(booked<capacity)
{
return true;
}
return false;
}
public static int addBooking(Booking Bking) throws SQLException
{
Connection con = DBConnection.getConnection();
String Q = "insert into booking(passenger_name, bus_no, travel_date) value(?,?,?)";
PreparedStatement pdt = con.prepareStatement(Q);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
pdt.setString(1,Bking.PassengerName);
pdt.setInt(2, Booking.BusNo);
pdt.setDate(3, sqlDate);
int row = pdt.executeUpdate();
return row;
}
}