public int ReadFile2DB(File TargetFile, String host, String hostPath, String FileURL, DatabaseAccess JavaDBAccess, boolean ConfirmDialog) {
        PreparedStatement ps = null;
        int TARGET_PHP_FILES_ID = 0, TARGET_PHP_WEB_APPLICATION_ID = -1, count = 0, fileLength = 0;
        String Line = "", PHPFileTextClean = "";
        ResultSet rs = null;
        // Adapted from http://developers.sun.com/docs/javadb/10.2.2/ref/rrefclob.html
        try {
            conn.setAutoCommit(false);

            if (TargetFile.getName().toLowerCase().endsWith(".php")) {//only works with .php files
                // Test to see if the TARGET_PHP_WEB_APPLICATIONS is already in the DB

                ps = conn.prepareStatement("SELECT COUNT(*) FROM TARGET_PHP_WEB_APPLICATIONS WHERE HOST=? AND HOST_PATH=?");
                ps.setString(1, host);
                ps.setString(2, hostPath);

                rs = ps.executeQuery(); // get the result

                rs.next();
                count = rs.getInt(1);
                rs.close();
                ps.close();

                if (count == 0) {// Inserts the Target PHP file

                    ps = conn.prepareStatement("INSERT INTO TARGET_PHP_WEB_APPLICATIONS (ID, HOST, HOST_PATH, ACTIVE) VALUES (DEFAULT,?,?,'Y')", Statement.RETURN_GENERATED_KEYS);
                    ps.setString(1, host);
                    ps.setString(2, hostPath);
                    ps.execute();

                    rs = ps.getGeneratedKeys(); // get the auto increment column key value

                    rs.next();
                    TARGET_PHP_WEB_APPLICATION_ID = rs.getInt(1);
                    rs.close();

                } else {// gets the primary key

                    ps = conn.prepareStatement("SELECT ID FROM TARGET_PHP_WEB_APPLICATIONS WHERE HOST=? AND HOST_PATH=?");
                    ps.setString(1, host);
                    ps.setString(2, hostPath);

                    rs = ps.executeQuery(); // get the result

                    rs.next();
                    TARGET_PHP_WEB_APPLICATION_ID = rs.getInt(1);
                    rs.close();
                    ps.close();
                }


                // Test to see if the Target PHP file is already in the DB
                ps = conn.prepareStatement("SELECT COUNT(*) FROM TARGET_PHP_FILES WHERE PATH=?");
                ps.setString(1, TargetFile.getAbsolutePath());

                rs = ps.executeQuery(); // get the result

                rs.next();
                count = rs.getInt(1);
                rs.close();
                ps.close();

                if (count == 0) {// Inserts the Target PHP file

                    fileLength = (int) TargetFile.length();
                    // - first, create an input stream
                    InputStream fin = new FileInputStream(TargetFile);

                    // Start a transaction by inserting a record in the TARGET_PHP_FILES table
                    ps = conn.prepareStatement("INSERT INTO TARGET_PHP_FILES (ID, TARGET_PHP_WEB_APPLICATION, NAME, URL, PATH, TEXT, CLEANED_TEXT, ACTIVE) VALUES(DEFAULT,?,?,?,?,?,?,'Y')", Statement.RETURN_GENERATED_KEYS);
                    ps.setInt(1, TARGET_PHP_WEB_APPLICATION_ID);
                    ps.setString(2, TargetFile.getName());
                    ps.setString(3, FileURL);
                    ps.setString(4, TargetFile.getAbsolutePath());
                    // - set the value of the input parameter to the input stream
                    ps.setAsciiStream(5, fin, fileLength);
                    ps.setNull(6, java.sql.Types.CLOB);//CLEANED_TEXT

                    ps.execute();

                    rs = ps.getGeneratedKeys(); // get the auto increment column key value

                    rs.next();
                    TARGET_PHP_FILES_ID = rs.getInt(1);
                    System.out.println("Chave usada: " + TARGET_PHP_FILES_ID);
                    rs.close();
                    //Cleans the PHP file text 
                    PHPFileTextClean = CleanPHPFile(TARGET_PHP_FILES_ID, JavaDBAccess);
                } else {// The file already exists in the DB

                    int n = JOptionPane.YES_OPTION;
                    if (ConfirmDialog) {
                        n = 0;
                        n = JOptionPane.showConfirmDialog(new JFrame(), "The file\n" + TargetFile.getAbsolutePath() + "\nalready exists in the database.\nIf you decide to update the file all the results based on it will be deleted\nDo you want to update the file?", "Attention!", JOptionPane.ERROR_MESSAGE, JOptionPane.YES_NO_OPTION);
                    }
                    if (n == JOptionPane.YES_OPTION) {//updates the file

                        // Clean previous vulnerability injections in the same file
                        System.out.println(TargetFile.getAbsolutePath());
                        ps = conn.prepareStatement("DELETE FROM VULNERABILITY_INJECTION_RESULTS WHERE ID IN (SELECT VULNERABILITY_INJECTION_RESULTS.ID FROM VULNERABILITY_INJECTION_RESULTS, TARGET_PHP_FILES WHERE TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND TARGET_PHP_FILES.PATH=?)");
                        ps.setString(1, TargetFile.getAbsolutePath());
                        ps.execute();
                        conn.commit();

                        // Updates the Target PHP file
                        ps = conn.prepareStatement("SELECT ID FROM TARGET_PHP_FILES WHERE PATH=?");
                        ps.setString(1, TargetFile.getAbsolutePath());

                        rs = ps.executeQuery(); // get the result

                        rs.next();
                        TARGET_PHP_FILES_ID = rs.getInt(1);
                        rs.close();

                        fileLength = (int) TargetFile.length();
                        // - first, create an input stream
                        InputStream fin = new FileInputStream(TargetFile);

                        // Start a transaction by inserting a record in the TARGET_PHP_FILES table
                        ps = conn.prepareStatement("UPDATE TARGET_PHP_FILES SET TEXT=? WHERE ID=?");
                        // - set the value of the input parameter to the input stream
                        ps.setAsciiStream(1, fin, fileLength);
                        ps.setInt(2, TARGET_PHP_FILES_ID);
                        ps.execute();
                        rs.close();
                        //Cleans the PHP file text 
                        PHPFileTextClean = CleanPHPFile(TARGET_PHP_FILES_ID, JavaDBAccess);
                    }
                }
                conn.commit();
                ps.close();
            }
        } catch (Throwable e) {
            System.out.println("Errors in ReadFile2DB!");
            System.out.println("exception thrown:");

            if (e instanceof SQLException) {
                printSQLError((SQLException) e);
            } else {
                e.printStackTrace();
            }
        }
        return TARGET_PHP_FILES_ID;
    }