-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjdbcInsertionDynamically.java
More file actions
73 lines (52 loc) · 1.62 KB
/
jdbcInsertionDynamically.java
File metadata and controls
73 lines (52 loc) · 1.62 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 databseInsertionDynamicallyJDBC;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class jdbcInsertionDynamically {
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con=null;
Statement st=null;
BufferedReader br=null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/harendradb", "root", "root@123");
st=con.createStatement();
br =new BufferedReader(new InputStreamReader(System.in));
while(true) {
System.out.println("Enter Employee Number ");
int eno=Integer.parseInt(br.readLine());
System.out.println("Enter tha Employee name");
String ename=br.readLine();
System.out.println("Enter the Employee Salary");
float esal=Float.parseFloat(br.readLine());
System.out.println("Enter the Employee address");
String eadd=br.readLine();
String query="insert into employee value("+eno+",'"+ename+"','"+esal+"','"+eadd+"')";
st.executeUpdate(query);
System.out.print("Do you want add more employee? [y/n] :");
String option=br.readLine();
if(option.equalsIgnoreCase("y")) {
continue;
}else {
break;
}
}
System.out.println("Employee Inserted Successfully");
}catch(Exception e) {
e.printStackTrace();
}
finally {
try {
br.close();
st.close();
con.close();
}catch(Exception e2)
{
e2.printStackTrace();
}
}
}
}