コード例 #1
0
 public String connectWithDetail(Student student) {
   try {
     connectWithMySql();
     String sql =
         "INSERT INTO webservicedemo (Name, Roll, Mobile, Email, Pass) VALUES (?,?,?,?,?)";
     PreparedStatement ps = conn.prepareStatement(sql);
     ps.setString(1, student.getName());
     ps.setString(2, student.getRoll());
     ps.setString(3, student.getMobile());
     ps.setString(4, student.getEmail());
     ps.setString(5, student.getPass());
     int n = ps.executeUpdate();
     if (n > 0) {
       ret = "SUCCESS";
     }
   } catch (SQLException e) {
     ret = "ERROR";
   } finally {
     if (conn != null) {
       try {
         conn.close();
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
   return ret;
 }
コード例 #2
0
  public String connectAs(Student student) {

    try {
      connectWithMySql();
      String sql = "SELECT * FROM webservicedemo WHERE Roll = ? AND Pass=?";
      PreparedStatement ps = conn.prepareStatement(sql);
      ps.setString(1, student.getRoll());
      ps.setString(2, student.getPass());
      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        student.setName(rs.getString(1));
        student.setMobile(rs.getString(3));
        student.setEmail(rs.getString(4));
        // student.setPass(rs.getString(5));
        ret = "SUCCESS";
      }
    } catch (SQLException e) {
      ret = "ERROR";
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    return ret;
  }