Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.     /**
  2.      * Method for checking if a sheep with ID already exists in the database.
  3.      * @param sheep_id ID to be checked in the database.
  4.      * @return Return a boolean value of the result.
  5.      */
  6.     public boolean sheepExists(int sheep_id){
  7.         openConnectionToDatabase();
  8.         int id = -1;
  9.         try{
  10.             stmt.executeQuery("SELECT sau_id FROM SauInfo WHERE sau_id="+sheep_id+";");
  11.             rs = stmt.getResultSet();
  12.            
  13.             if(rs.next()){
  14.                 id = rs.getInt(1);
  15.                 if(id == sheep_id){
  16.                     return true;
  17.                 }
  18.             }
  19.            
  20.         }catch(SQLException ex){
  21.             System.out.println("(sheepExists)SQLException: " + ex.getMessage());
  22.             System.out.println("(sheepExists)SQLState: " + ex.getSQLState());
  23.             System.out.println("(sheepExists)VendorError: " + ex.getErrorCode());  
  24.         }finally{
  25.             closeConnectionToDatabase();
  26.         }
  27.         return false;
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement