Question-1 Implement the Employee DAO Factory & JDBC
Answer:-
package temp;
public class EmployeeDAOFactory {
public static void main(String[] args){
EmployeeDAOJDBCImpl edji=new EmployeeDAOJDBCImpl();
edji.AddEmployee(1,"hita", "IT");
edji.AddEmployee(2, "meenal", "IT");
edji.AddEmployee(3, "deepika", "IT");
edji.AddEmployee(4, "aniket", "IT");
edji.AddEmployee(5, "piyu", "HR");
edji.RemoveEmployee(5, "piyu", "HR");
}
}
package temp;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class EmployeeDAOJDBCImpl {
Connection con;
String query1,query2;
public EmployeeDAOJDBCImpl(){
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/Employee","root","root");
System.out.println("Database connected successfully");
} catch (ClassNotFoundException ex) {
System.out.println("Driver not found");
} catch (SQLException ex) {
System.out.println("DB not found");
}
}
public void AddEmployee(int id,String name,String depart){
try {
query1="insert into employee values(?,?,?)";
PreparedStatement pst1=con.prepareStatement(query1);
pst1.setInt(1, id);
pst1.setString(2, name);
pst1.setString(3, depart);
pst1.executeUpdate();
System.out.println("Added"+name);
} catch (SQLException ex) {
System.out.println("Error in data");
}
}
public void RemoveEmployee(int id,String name,String depart){
try {
query2="delete from Employee where id=? name=? depart=? ";
PreparedStatement pst2=con.prepareStatement(query2);
pst2.setInt(1, id);
pst2.setString(2, name);
pst2.setString(3, depart);
pst2.executeUpdate();
System.out.println("Removed"+name);
} catch (SQLException ex) {
System.out.println("Error in data");
}
}
}
Question-2 Read,Write the file using Buffered Reader.
Answer:-
i need this
ReplyDelete