Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Method for checking if a sheep with ID already exists in the database.
- * @param sheep_id ID to be checked in the database.
- * @return Return a boolean value of the result.
- */
- public boolean sheepExists(int sheep_id){
- openConnectionToDatabase();
- int id = -1;
- try{
- stmt.executeQuery("SELECT sau_id FROM SauInfo WHERE sau_id="+sheep_id+";");
- rs = stmt.getResultSet();
- if(rs.next()){
- id = rs.getInt(1);
- if(id == sheep_id){
- return true;
- }
- }
- }catch(SQLException ex){
- System.out.println("(sheepExists)SQLException: " + ex.getMessage());
- System.out.println("(sheepExists)SQLState: " + ex.getSQLState());
- System.out.println("(sheepExists)VendorError: " + ex.getErrorCode());
- }finally{
- closeConnectionToDatabase();
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement