import java.io.DataInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DeleteQueryEx {
public static void main(String[] args){
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
String url = "jdbc:derby://localhost:1527/hari";
con = DriverManager.getConnection(url, "app","app");
stmt = con.createStatement();
System.out.println("Please enter the employee number");
DataInputStream din = new DataInputStream(System.in);
String ids = din.readLine();
int id = Integer.parseInt(ids);
String query = "delete from MYEMP where ENO = "+id;
int count = stmt.executeUpdate(query);
System.out.println(count + " Records deleted.");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}catch (SQLException ex1) {
ex1.printStackTrace();
}catch(IOException ex3){
ex3.printStackTrace();
}
// System.out.println("Hi");
}
}
No comments:
Post a Comment