import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletNaturalJoiningTables 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 LEFT JOIN "+"emp_sal");
ResultSet rs = pst.executeQuery();
pw.println("UserId" + "\t" + "Firstname" + "\t" + "Salary"+"
");
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 + "
");
}
}
catch (Exception e) {
pw.println("The statement is not executed");
}
}
}