Professional Documents
Culture Documents
catch(SQLException s){
System.out.println(s);
}
}
static void insloop() throws SQLException, IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
;
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:330
6/Sample","root","Adi89Ani96");
PreparedStatement n = con.prepareStatement("insert into student values(?
,?)");
do{
System.out.println("ENTER ID");
int pid = Integer.parseInt(br.readLine());
System.out.println("ENTER NAME");
String pname = br.readLine();
n.setInt(1, pid);
n.setString(2,pname);
int i = n.executeUpdate();
System.out.println("DO YOU WANT TO CONTINUE??");
String ch = br.readLine();
if(ch.startsWith("n") || ch.startsWith("N")){
break;
}
}while(true);
con.close();
}
static void delete() throws SQLException, IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
;
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:330
6/Sample","root","Adi89Ani96");
PreparedStatement n = con.prepareStatement("delete from student where id
= ?");
do{
try{
System.out.println("Enter ID");
int pid = Integer.parseInt(br.readLine());
n.setInt(1,pid);
int p = n.executeUpdate();
System.out.println("DELETION DONE");
}
catch(Exception e){
System.out.println(e.getMessage());
}
System.out.println("DO YOU WANT TO CONTINUE??");
String ch = br.readLine();
if(ch.startsWith("n") || ch.startsWith("N")){
break;
}
}while(true);
con.close();
}
}