-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperation.java
More file actions
125 lines (109 loc) · 3.23 KB
/
Operation.java
File metadata and controls
125 lines (109 loc) · 3.23 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
import java.util.*;
import java.sql.*;
public class Operation extends DBConnection
{
void insert()
{
try
{
Scanner sc1 = new Scanner(System.in);
System.out.println("Enter employee id ");
int id=sc1.nextInt();
System.out.println("Enter employee name ");
String name=sc1.next();
String insertquerry="insert into employee values(?,?);";
PreparedStatement pst=con.prepareStatement(insertquerry);
pst.setInt(1, id);
pst.setString(2,name);
pst.executeUpdate();
System.out.println("data inserteddd...................");
}
catch(Exception e)
{
System.out.println("");
}
}
void delete()
{
try
{
int id=2;
String delquery="delete from employee where id="+id;
//String course="BCA";
// String delquery="delete from student where scourse='"+course+"'";
PreparedStatement pst2=con.prepareStatement(delquery);
pst2.executeUpdate();
System.out.println("data deleteddddddddddddd....");
}
catch(Exception e)
{
System.out.println("not deleteddd..."+e);
}
}
void view()
{
try
{
String viewquery="select * from employee";
Statement stmt=con.createStatement();
ResultSet rs = stmt.executeQuery(viewquery);
while(rs.next())
{
System.out.print(" "+rs.getInt(1));
System.out.print(" "+rs.getString(2));
System.out.print("\n");
}
System.out.println("view fn working ");
}
catch(Exception e)
{
System.out.println("");
}
}
void update()
{
try
{
System.out.println("update fn working ");
}
catch(Exception e)
{
System.out.println("");
}
}
public static void main(String args[])
{
Operation obj = new Operation();
while(true)
{
System.out.println("\nPress 1 for insert");
System.out.println("Press 2 for delete");
System.out.println("Press 3 for view");
System.out.println("Press 4 for update");
System.out.println("Press 5 for Exit");
System.out.println("\nEnter ur choice ");
Scanner sc1 = new Scanner(System.in);
int choice = sc1.nextInt();
switch(choice)
{
case 1:
obj.insert();
break;
case 2:
obj.delete();
break;
case 3:
obj.view();
break;
case 4:
obj.update();
break;
case 5:
System.exit(0);
break;
default:
System.out.println("Wrong choice ");
}
}
}
}