-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_in_jdbc.java
36 lines (32 loc) · 1.14 KB
/
fetch_in_jdbc.java
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
import java.io.*;
import java.sql.*;
class fetch{
public static void main(String args[])throws IOException
{
DataInputStream ds = new DataInputStream(System.in);
System.out.println("enter empid whose data is to be fetched");
String eno=ds.readLine();
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
Statement stmt = con.createStatement();
String q1 = "select * from e_reg where e_id='"+eno+"'";
ResultSet rs = stmt.executeQuery(q1);
if(rs.next())
{
System.out.println("emp_id is "+rs.getString(1));
System.out.println("emp_name is "+rs.getString(2));
System.out.println("emp_contact is "+rs.getString(3));
}
else
{
System.out.println("not found");
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}