import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletJoiningTables extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		String connectionURL = "jdbc:mysql://localhost/zulfiqar";
		Connection connection;
		try{
			Class.forName("org.gjt.mm.mysql.Driver");
			connection = DriverManager.getConnection(connectionURL, "root", "admin");
			PreparedStatement pst = connection.prepareStatement("SELECT *FROM "+"emp_details"+" NATURAL JOIN "+"Emp_sal");
			ResultSet rs = pst.executeQuery();
			pw.println("UserId" + "\t\t" + "Name" + "\t\t" + "Salary"+"<br>");
			while(rs.next()){
				String id = rs.getString("userId");
				String name = rs.getString("Name");
				String sal = rs.getString("salary");
				pw.println(id + "\t\t" + name + "\t\t" + sal + "<br>");
			}
		}
		catch (Exception e){
			pw.println("The statement is not executed");
		}
	}
}