-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentDatabase.java
52 lines (44 loc) · 1.46 KB
/
StudentDatabase.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package rank;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
public class StudentDatabase
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","Xyz!3456789");
Statement s=c.createStatement();
//s.executeUpdate("create table student1(id int, name varchar(100),department varchar(10))");
char cc='Y';
PreparedStatement pt1=c.prepareStatement("insert into student1 values(?,?,?)");
do
{
System.out.println("Enter The Id-");
pt1.setInt(1, Integer.parseInt(br.readLine()));
System.out.println("Enter The Name-");
pt1.setString(2, br.readLine());
System.out.println("Enter The Department-");
pt1.setString(3, br.readLine());
System.out.println("Want To Add More? Y?N");
cc=br.readLine().charAt(0);
}while(cc=='Y');
pt1.executeUpdate();
ResultSet rs=s.executeQuery("select * from student1 where id=1");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
c.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}