Skip to main content

Posts

Showing posts from September, 2023

How to Connect MySQL Database in Java

Connect MySQL Database in Java Since Java is one of the more popular programming languages, it naturally offers strong support for databases. Using JDBC (Java Database Connectivity), we are able to establish connections to numerous databases. Here, you'll learn how to use JDBC to communicate with a database while running queries. Introduction JDBC is the default Java API for establishing connections to common relational databases. Here, you'll learn how to utilize Java as well as JDBC to connect to MySQL databases hosted on Azure.   In this post, we'll cover two different kinds of authentication: those based on Azure Active Directory (Azure AD) as well as those based on MySQL. To see how Azure Active Directory authentication works, click the Passwordless tab, while the Password tab displays MySQL authentication.   Linking to Azure Database for MySQL with an Azure Active Directory account is possible via the Azure AD authentication mechanism. Using Azure Active Directory (A

Queen's Attack II HackerRank Solution in Java with Explanation

Queen's Attack II Problem's Solution in Java (Chessboard Problem)   Problem Description : You will be given a square chess board with one queen and a number of obstacles placed on it. Determine how many squares the queen can attack.  A queen is standing on an n * n chessboard. The chess board's rows are numbered from 1 to n, going from bottom to top. Its columns are numbered from 1 to n, going from left to right. Each square is referenced by a tuple, (r, c), describing the row r and column c, where the square is located. The queen is standing at position (r_q, c_q). In a single move, queen can attack any square in any of the eight directions The queen can move: Horizontally (left, right) Vertically (up, down) Diagonally (four directions: up-left, up-right, down-left, down-right) The queen can move any number of squares in any of these directions, but it cannot move through obstacles. Input Format : n : The size of the chessboard ( n x n ). k : The number of obstacles.