webApp2/src/main/java/video/video.java
public Boolean is_video_in_db(){
        Boolean result = true;
        String query = "select count(*) from videos where title=?";
        Connection c = null;
        try{
            // create connection to db
            c = DriverManager.getConnection("jdbc:derby://localhost:1527/isdcm_lab_db;user=isdcm_lab_db;password=isdcm_lab_db");
            
            // prepare statement
            PreparedStatement statement;
            statement = c.prepareStatement(query);
            statement.setString(1, this.getTitulo());
            
            // execute query and analyse results
            ResultSet r = statement.executeQuery();
        if (r.next())
            {
                if (r.getInt(1) == 0) //if the number of video == 0
                    result = false;   //then video does not exist yet
            }    
        }catch (SQLException e) {
            System.out.println(Arrays.toString(e.getStackTrace()));
        } finally {
            try {
                if (c != null) 
                    c.close();                
            } catch (SQLException e) {
                System.out.println(Arrays.toString(e.getStackTrace()));
            }
        }
        return result;
    }
//to check if a video already exist in the db
to check if a video already exist in the db
to check if a video already exist in the db
public Boolean is_video_in_db(){
        Boolean result = true;
        String query = "select count(*) from videos where title=?";
        Connection c = null;
        try{
            c = DriverManager.getConnection("jdbc:derby://localhost:1527/isdcm_lab_db;user=isdcm_lab_db;password=isdcm_lab_db");
            PreparedStatement statement;
            statement = c.prepareStatement(query);
            statement.setString(1, this.getTitulo());
            ResultSet r = statement.executeQuery();
        if (r.next())
            {
                if (r.getInt(1) == 0) 
                    result = false;   
            }    
        }catch (SQLException e) {
            System.out.println(Arrays.toString(e.getStackTrace()));
        } finally {
            try {
                if (c != null) 
                    c.close();                
            } catch (SQLException e) {
                System.out.println(Arrays.toString(e.getStackTrace()));
            }
        }
        return result;
    }
public Boolean is_video_in_db ( ) { Boolean result = true ; String query = "select count(*) from videos where title=?" ; Connection c = null ; try { c = DriverManager . getConnection ( "jdbc:derby://localhost:1527/isdcm_lab_db;user=isdcm_lab_db;password=isdcm_lab_db" ) ; PreparedStatement statement ; statement = c . prepareStatement ( query ) ; statement . setString ( 1 , this . getTitulo ( ) ) ; ResultSet r = statement . executeQuery ( ) ; if ( r . next ( ) ) { if ( r . getInt ( 1 ) == 0 ) result = false ; } } catch ( SQLException e ) { System . out . println ( Arrays . toString ( e . getStackTrace ( ) ) ) ; } finally { try { if ( c != null ) c . close ( ) ; } catch ( SQLException e ) { System . out . println ( Arrays . toString ( e . getStackTrace ( ) ) ) ; } } return result ; }
to check if a video already exist in the db
to check if a video already exist in the db
// create connection to db // prepare statement // execute query and analyse results //if the number of video == 0 //then video does not exist yet