package com.complet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class DatabaseConnection {
    public static Connection dbcon;
    public static Statement stmt;
    public static void openDatabaseConnection() {
		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			dbcon = DriverManager.getConnection(
					"jdbc:sqlserver://".concat(GetCredentials.getSqlServerPath()).concat(";databaseName=")
					.concat(GetCredentials.getDbName()).concat(";user=").concat(GetCredentials.getDbUser())
					.concat(";password=").concat(GetCredentials.getDbPassword()).concat(";"));
		    stmt = dbcon.createStatement();
		 } catch (SQLException sqle) {
			System.err.println(sqle);
		 } catch (Exception e) {
			System.err.println(e);
		 }
	}
	public static void closeDatabaseConnection() {
		try {
			openDatabaseConnection();
			stmt.close();
			dbcon.close();
		} catch (SQLException sqle) {
			System.err.println(sqle);
		} catch (Exception e) {
			System.err.println(e);
		} finally {
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException sqle2) {
				System.err.println(sqle2);
			}
			try {
				if (dbcon != null) {
					dbcon.close();
				}
			} catch (SQLException sqle) {
				System.err.println(sqle);
			}
		}
     }

	public static void InsertData(ArrayList<String> array, String path) {
		try {
			String pathHtml;
			int position;
			openDatabaseConnection();
		    for(int i = 0; i < array.size(); i++) {
		        position = i;
				pathHtml = path + "/" + Integer.toString(i) + ".html";
				stmt.executeUpdate("INSERT INTO DatabaseOfURLs VALUES('" + position + "','" + array.get(i) + "','" + pathHtml + "')");
            }
    		stmt.close();
		    dbcon.close();

        } catch (SQLException sqle) {
			System.err.println(sqle);
		} catch (Exception e) {
			System.err.println(e);
		} finally {
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException sqle2) {
				System.err.println(sqle2);
			}
			try {
				if (dbcon != null) {
					dbcon.close();
				}
			} catch (SQLException sqle) {
				System.err.println(sqle);
			}
		}
	}
}
@@ -322,16 +322,82 @@
 %09%09try %7B%0A
+%09%09%09GetCredentials.dbCredentials(%22path DataBase-Credentials.txt%22);%0A
 %09%09%09Class
@@ -2284,9 +2284,280 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09public static void deleteData(String dbName) %7B%0A%09%09try %7B%0A%09%09%09openDatabaseConnection();%0A%09%09%09stmt.executeUpdate(%22DELETE FROM %22 + dbName + %22;%22); //Deletes data from the dbName table%0A%09%09%09closeDatabaseConnection();%0A%09%09%7D catch (SQLException e) %7B%0A%09%09%09System.err.println(e);%0A%09%09%7D%0A    %7D%0A
 %7D

Create a method to delete data from Database and use method getCredentials