-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEmployeeRtJdbc.java
More file actions
41 lines (31 loc) · 1.03 KB
/
EmployeeRtJdbc.java
File metadata and controls
41 lines (31 loc) · 1.03 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class EmployeeRt {
public static void main(String[] args) {
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Enter Employee Id:");
int empId = Integer.parseInt(br.readLine());
Connection con = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/test","sa","");
String query = "select * from Employee where EMPID = ?";
PreparedStatement st = con.prepareStatement(query);
st.setInt(1, empId);
ResultSet rs = st.executeQuery();
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
rs.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}