-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData1.java
More file actions
136 lines (131 loc) · 3.26 KB
/
Data1.java
File metadata and controls
136 lines (131 loc) · 3.26 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
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
134
135
136
package Schedule;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.*;
class Data1
{
Connection conn;
Statement stmt;
String event,date,time,query;
Scanner sc;
int choice,choice1;
Data1()
{
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Driver");
//Connection
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/schedule","root","");
//creating statement
stmt=conn.createStatement();
//creating scanner object
sc=new Scanner(System.in);
}
catch(Exception e)
{
System.out.println(e);
}
}
void operations()
{
try
{
System.out.println("------------My Schedule----------");
System.out.println("Enter 1 for entering details");
System.out.println("Enter 2 for printing details");
System.out.println("Enter 3 for deleting particular schedule");
System.out.println("Enter 4 for Exit");
choice=sc.nextInt();
boolean b=true;
while(b==true)
{
switch(choice)
{
case 1:
details();
break;
case 2:
print();
break;
case 3:
delete();
break;
default:
b=false;
System.out.println("Exiting");
System.exit(0);
}
System.out.println("-----------------------------");
System.out.println("Enter 1 for entering details");
System.out.println("Enter 2 for printing details");
System.out.println("Enter 3 for deleting particular schedule");
System.out.println("Enter 4 for Exit");
choice=sc.nextInt();
}
}
catch(Exception e)
{
System.out.println("Error "+e.getMessage());
}
}
void details()
{
try
{
System.out.println("Enter the type of event");
event=sc.next();
System.out.println("Enter the Time of event as hh:mm:ss");
time=sc.next();
System.out.println("Enter the Date of event as yy:mm:dd");
date=sc.next();
query="insert into schedule_details values('"+event+"','"+time+"','"+date+"')";
stmt.execute(query);
System.out.println("--------Data Entered Successfully-----------");
}
catch(Exception e)
{
System.out.println("Error : "+e.getMessage());
}
}
void print()
{
try
{
System.out.println("Enter date of event");
date=sc.next();
System.out.println("Enter type of event");
event=sc.next();
query="select * from schedule_details where Date='"+date+"' and Event_Type='"+event+"'";
ResultSet pointer=stmt.executeQuery(query);
while(pointer.next())
{
System.out.println("Event Type : "+pointer.getString(1)+" Time : "+pointer.getString(2)+" Date : "+pointer.getString(3));
}
}
catch(Exception e)
{
System.out.println("Error : "+e.getMessage());
}
}
void delete()
{
try
{
System.out.println("Enter name of event you want to delete");
event=sc.next();
System.out.println("Enter Date ");
date=sc.next();
query="delete from schedule_details where Event_type='"+event+"' and Date='"+date+"'";
stmt.execute(query);
System.out.println("-------------Deleted Successfully---------------");
}
catch(Exception e)
{
System.out.println("Error : "+e.getMessage());
}
}
}