-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror java hashmap
More file actions
72 lines (63 loc) · 1.59 KB
/
error java hashmap
File metadata and controls
72 lines (63 loc) · 1.59 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 com.ct.day9;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map.Entry;
public class SqlDemo1 {
public static void main(String[] args) throws SQLException {
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","root");
String qry="SELECT * FROM Employee";
Statement st= con.createStatement();
ResultSet rs=st.executeQuery(qry);
Empl emp=new Empl();
HashMap<Integer,Empl> empList=new HashMap<Integer,Empl>();
while(rs.next()) {
emp.setEmpid(rs.getInt("emp_id"));
emp.setName(rs.getString(2));
emp.setSurName(rs.getString(3));
emp.setJob(rs.getString(4));
System.out.println("data "+emp);
empList.put(emp.getEmpid(), emp);
}
System.out.println("hash map data "+empList);
for(Entry em : empList.entrySet())
System.out.println(em.getKey()+" "+em.getValue());
}
}
class Empl{
int empid;
String name;
String surName;
String job;
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurName() {
return surName;
}
public void setSurName(String surName) {
this.surName = surName;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
@Override
public String toString() {
return "Empl [empid=" + empid + ", name=" + name + ", surName=" + surName + ", job=" + job + "]";
}
}