import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class vuser extends HttpServlet { 

	HttpServletRequest req;
	HttpServletResponse res;
//getting info from the HTML page what the user typed in
	String user=req.getParameter("user");
	String passwd=req.getParameter("password");
	String DBownertype=req.getParameter("dbownertype");	

	private ConnectionPool pool;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		try {
			pool = new ConnectionPool(dbl, user, passwd, "oracle.jdbc.driver.OracleDriver", 2,1);
		}
		catch (Exception e) {
			throw new UnavailableException(this, "Couldn't create ConnectionPool");
		}
	}
	
	public void dostuff (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
    		HttpSession tsession=req.getSession(true);
	  	res.setContentType("text/html");
	  	PrintWriter os=res.getWriter();

	//HTML PART

	//Shows Table of roles created
		String table=(("SELECT USERNAME, ROLE FROM ") + user + (".users ORDER BY USERNAME"));

		try {	
			con = pool.getConnection();
			stmt = con.createStatement();
			rs = stmt.executeQuery(table);
			os.println("<TABLE CELLSPACING=0 BORDER=1 WIDTH=50%>");
			while (rs.next()) {
				String u = rs.getString("USERNAME");
				String r = rs.getString("ROLE");
				os.println("<tr><td>" + u + "</td><td>" + r + "</td></tr>");
			}//end while
			
		}
		catch(Exception ex) {
			System.out.println("Sorry no users have been created yet!<p><br>");
			try {
				con.rollback();
			}
			catch (Exception ignored) {}
				os.println("Comand failed. Please contact technical support");
			}
			finally {
				if (con != null) pool.returnConnection(con);
				try {
					if (stmt != null) stmt.close();
					if (rs != null) rs.close();
				}
				catch (SQLException ignored) {}
			}
	
	}
	public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    	dostuff(req, res);}

	public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    	dostuff(req, res);}
}