Пример #1
0
 @Override
 public int updateDao(Object obj) {
   Connection con = MysqlCon.getConnection();
   String sql =
       "update course set code=?, depart_code=?, subject=?, "
           + "material=?, prof_code=? where code = ?";
   PreparedStatement pstmt = null;
   Course course = (Course) obj;
   try {
     pstmt = con.prepareStatement(sql);
     pstmt.setInt(1, course.getCode());
     pstmt.setInt(2, course.getDepart_code());
     pstmt.setString(3, course.getSubject());
     pstmt.setString(4, course.getMaterial());
     pstmt.setInt(5, course.getProf_code());
     pstmt.setInt(6, course.getCode());
     pstmt.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
     return -1;
   } finally {
     try {
       pstmt.close();
       con.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   return 0;
 }
Пример #2
0
 @Override
 public int insertDao(Object obj) {
   Connection con = MysqlCon.getConnection();
   String sql =
       "insert into course (code, depart_code, subject, material, prof_code) values "
           + "(?, ?, ?, ?, ?) ";
   PreparedStatement pstmt = null;
   Course course = (Course) obj;
   try {
     pstmt = con.prepareStatement(sql);
     pstmt.setInt(1, course.getCode());
     pstmt.setInt(2, course.getDepart_code());
     pstmt.setString(3, course.getSubject());
     pstmt.setString(4, course.getMaterial());
     pstmt.setInt(5, course.getProf_code());
     pstmt.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
     return -1;
   } finally {
     try {
       pstmt.close();
       con.close();
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   return 0;
 }