webApp2/src/main/java/video/video.java
public String add_video_to_db(){
        String result = "Error when adding video to database";
        // define query
        String query = "insert into videos(\"TITLE\",\"AUTHOR\",\"UPDATE_DATE\",\"TIME\",\"NB_OF_REPRODUCTIONS\",\"DESCRIPTION\",\"FORMAT\") values(?,?,?,?,?,?,?)";
        Connection c = null;
        try{
            // create a database connection
            result ="enter into try";
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            result="before connection";            
            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());
            statement.setString(2,this.getAutor());
            statement.setString(3,this.getFecha_creacion());
            statement.setString(4,this.getDuracion());
            statement.setInt(5,this.getNum_reproduccion());
            statement.setString(6,this.getDescripcion());
            statement.setString(7,this.getFormato());
            
            // execute query
            int i = statement.executeUpdate();
            result = "Video successfully added to database";
        }catch (ClassNotFoundException | 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 register a video in the database
to register a video in the database
to register a video in the database
public String add_video_to_db(){
        String result = "Error when adding video to database";
        String query = "insert into videos(\"TITLE\",\"AUTHOR\",\"UPDATE_DATE\",\"TIME\",\"NB_OF_REPRODUCTIONS\",\"DESCRIPTION\",\"FORMAT\") values(?,?,?,?,?,?,?)";
        Connection c = null;
        try{
            result ="enter into try";
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            result="before connection";            
            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());
            statement.setString(2,this.getAutor());
            statement.setString(3,this.getFecha_creacion());
            statement.setString(4,this.getDuracion());
            statement.setInt(5,this.getNum_reproduccion());
            statement.setString(6,this.getDescripcion());
            statement.setString(7,this.getFormato());
            int i = statement.executeUpdate();
            result = "Video successfully added to database";
        }catch (ClassNotFoundException | 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 String add_video_to_db ( ) { String result = "Error when adding video to database" ; String query = "insert into videos(\"TITLE\",\"AUTHOR\",\"UPDATE_DATE\",\"TIME\",\"NB_OF_REPRODUCTIONS\",\"DESCRIPTION\",\"FORMAT\") values(?,?,?,?,?,?,?)" ; Connection c = null ; try { result = "enter into try" ; Class . forName ( "org.apache.derby.jdbc.ClientDriver" ) ; result = "before connection" ; 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 ( ) ) ; statement . setString ( 2 , this . getAutor ( ) ) ; statement . setString ( 3 , this . getFecha_creacion ( ) ) ; statement . setString ( 4 , this . getDuracion ( ) ) ; statement . setInt ( 5 , this . getNum_reproduccion ( ) ) ; statement . setString ( 6 , this . getDescripcion ( ) ) ; statement . setString ( 7 , this . getFormato ( ) ) ; int i = statement . executeUpdate ( ) ; result = "Video successfully added to database" ; } catch ( ClassNotFoundException | 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 register a video in the database
to register a video in the database
// define query // create a database connection // prepare statement // execute query