JDBC

public void add(Employee e) {
 Class.forName("oracle.jdbc.driver.OracleDriver");

 Connection con = DriverManager.getConnection(
    "jdbc:oracle:thin:@192.168.0.26:1521:tarena", "sd1004",
    "sd1004");
 PreparedStatement stmt = null;
 try { 
  stmt = con.prepareStatement("insert into employee(employeeid, employeename, roll,empstate,empentrydate) values(?,?,?,?,?)");
  stmt.setLong(1, e.getEmployeeId());
  stmt.setString(2, e.getEmployeeName());
  stmt.setString(3, e.getRoll());
  stmt.setString(4,e.getEmployeeState());
  stmt.setDate(5,e.getEmpoyeeEntryDate());
  stmt.executeUpdate();

  } catch (SQLException e) {
   e.printStackTrace();
   
  } finally {
   if(stmt != null){
    stmt.close();
   }
   if(con != null){
    con.close();
   }
  }
 }

 

 

你可能感兴趣的:(jdbc)