-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectWhereTest.java
More file actions
51 lines (41 loc) · 1.32 KB
/
Copy pathSelectWhereTest.java
File metadata and controls
51 lines (41 loc) · 1.32 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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
public class SelectWhereTest {
public static void main(String[] args) throws EmpNotFoundException {
try
{
System.out.println("");
DriverManager.registerDriver(new org.hsqldb.jdbc.JDBCDriver());
System.out.println("driver registered");
Connection con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/xdb", "SA", "");
Statement statement = con.createStatement();
System.out.println("statement created");
System.out.println("Enter employee id: ");
Scanner sc = new Scanner(System.in);
int empId = sc.nextInt();
ResultSet rs = statement.executeQuery("select * from employee where empno = "+empId);
if(rs.next())
{
System.out.println("Emp no: "+rs.getInt(1));
System.out.println("Emp name: "+rs.getString(2));
System.out.println("Emp salary: "+rs.getInt(3));
System.out.println("----------------------");
}
else
{
throw new EmpNotFoundException("Employee is not present with eployee id "+empId);
}
rs.close();
statement.close();
con.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}