-
Notifications
You must be signed in to change notification settings - Fork 1
/
schedule.java
136 lines (126 loc) · 2.91 KB
/
schedule.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Scanner;
class data
{
Statement stmt;
Connection conn;
Scanner sc;
int choice,choice2;
String event,date,time,query,query2,query3,udate,utime,uevent,ndate;
data()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/schedule","root","");
stmt=conn.createStatement();
sc=new Scanner(System.in);
}
catch(Exception e)
{
System.out.println("Connection failed");
}
}
void input()
{
try
{
System.out.println("-- Welcome to platform to get aware of upcoming events-");
System.out.println("Enter Date of event");
date=sc.next();
System.out.println("Enter time of event");
time=sc.next();
System.out.println("Enter event name");
event=sc.next();
query="insert into schedule values('"+date+"','"+time+"','"+event+"')";
stmt.execute(query);
System.out.println("------Data recorded Succesfuly-----");
System.out.println(" ");
boolean x=true;
boolean y=true;
while(x==true) {
System.out.println("Enter 1 to update record...... ");
System.out.println("Enter 2 to search record..... ");
System.out.println("Enter 3 to view record.....");
System.out.println("Enter 4 to exit.....");
choice=sc.nextInt();
if(choice==1)
{
while(y==true)
{
System.out.println("----Enter 1 to update date---");
System.out.println("----Enter 2 to update time---");
System.out.println("----Enter 3 to Exit----");
choice2=sc.nextInt();
switch(choice2)
{
case 1:
System.out.println("Enter new date");
udate=sc.next();
System.out.println("Enter name of event for which you want to update");
uevent=sc.next();
query2="update schedule set date='"+udate+"' where event='"+uevent+"' ";
stmt.execute(query2);
System.out.println("Updated successfully");
break;
case 2:
System.out.println("Enter new time");
utime=sc.next();
System.out.println("Enter name of event for which you want to update");
uevent=sc.next();
query2="update schedule set time='"+utime+"' where event='"+uevent+"' ";
stmt.execute(query2);
System.out.println("Updated successfully");
break;
case 3:
y=false;
break;
}}}
else if(choice==2)
{
System.out.println("choose the date for which you want to search event");
ndate=sc.next();
query2="select * from schedule where date='"+ndate+"' ";
stmt.execute(query2);
System.out.println("your schedule for this date is:");
ResultSet pointer=stmt.executeQuery(query2);
while(pointer.next())
{
System.out.println(pointer.getString(3));
}
}
else if(choice==3)
{
query3="select * from schedule";
ResultSet pointer=stmt.executeQuery(query3);
while(pointer.next())
{
System.out.println(pointer.getString(1)+" "+pointer.getString(2)+" "+pointer.getString(3));
}
}
else
{
x=false;
System.out.println("BYE!!!");
break;
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
public class schedule {
public static void main(String args[])
{
data p1=new data();
p1.input();
}
}