forked from sanjana091001/bus_booking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooking.java
71 lines (69 loc) · 1.81 KB
/
booking.java
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
package bus_booking;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
class booking implements bus_ticket_booking{
Connection c = null;
Statement stmt = null;
String boarding;
String destination;
int date;
int booking_id;
int booking_date;
booking(int d, String boa, String des)
{
date=d;
boarding=boa;
destination=des;
}
void addBooking(int pass_no,bus bus1 )
{
try
{
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/bus_ticket_booking", "postgres", "postgres");
c.setAutoCommit(false);
stmt = c.createStatement();
String sql = "UPDATE bus SET no_of_seats=no_of_seats-1 WHERE bus_id="+bus1.bus_id;
stmt.executeUpdate(sql);
c.commit();
System.out.println("Booked Succesfully");
stmt.close();
//ticket number not assigned
}
catch (Exception e)
{
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
}
public void payment()
{
//print amount
}
public void cancellation(int ticket_no, bus bus1)
{
try
{//after assigning ticket number
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/bus_ticket_booking", "postgres", "postgres");
c.setAutoCommit(false);
stmt = c.createStatement();
String sql = "UPDATE bus SET no_of_seats=no_of_seats+1 WHERE bus_id="+ bus1.bus_id+";";
stmt.executeUpdate(sql);
c.commit();
System.out.println("Booked Successfully");
stmt.close();
}
catch (Exception e)
{
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
}
};