Advertisement
Guest User

Untitled

a guest
Aug 8th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. public class Login extends HttpServlet {
  2. public static String user=null;
  3. public static String password=null;
  4. public static Connection con=null;
  5. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  6.  
  7.  
  8.  
  9. }
  10.  
  11. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  12.  
  13. }
  14. @Override
  15. public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
  16. getServletContext().getRequestDispatcher("/login.jsp").include(request, response);
  17. PrintWriter out=response.getWriter();
  18. response.setContentType("text/html");
  19.  
  20. user=request.getParameter("user");
  21. password=request.getParameter("pass");
  22. if(user !=null || password!=null){
  23. try{
  24. Class.forName("oracle.jdbc.driver.OracleDriver");
  25. con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1523:orcl",user,password);
  26. System.out.println("Conectare Reusita");
  27. javax.servlet.RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/Test");
  28. dispatcher.forward(request, response);
  29.  
  30. }catch(Exception e){
  31. out.println("<p align="center">"+e.getMessage()+"</p>");
  32. }
  33. }
  34.  
  35. out.close();
  36. }
  37. public static String getUser() {
  38. return user;
  39. }
  40. public static String getPassword() {
  41. return password;
  42. }
  43.  
  44. public static String table_selected= null;
  45. public static String[] col_selected= null;
  46. public static List <String> name_cols= new ArrayList<String>();
  47.  
  48. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  49.  
  50. }
  51.  
  52. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  53.  
  54. }
  55.  
  56. @Override
  57. public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
  58.  
  59. getServletContext().getRequestDispatcher("/tables.jsp").include(request, response);
  60.  
  61. PrintWriter out = response.getWriter();
  62.  
  63. response.setContentType("text/html");
  64.  
  65. try{
  66. String app = request.getParameter("app");
  67. col_selected=request.getParameterValues("q");
  68.  
  69. if(col_selected!=null){
  70.  
  71. for(int i=0;i<col_selected.length;i++){
  72.  
  73. name_cols.add(col_selected[i]);
  74. }
  75. }
  76.  
  77. System.out.println("cols:"+name_cols);
  78.  
  79. if(app !=null){
  80. if(app.equals("Manual_select")){
  81. RequestDispatcher dispatcher = request.getRequestDispatcher("/select_data.jsp");
  82. dispatcher.forward(request, response);
  83. }
  84.  
  85. if(app.equals("Show_cols")){
  86.  
  87. if(col_selected!=null){
  88. RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/cols_data.jsp");
  89. rd.include(request, response);
  90.  
  91. name_cols.clear();
  92.  
  93. }
  94.  
  95. }
  96.  
  97. }
  98.  
  99. out.close();
  100.  
  101. }catch(Exception e){
  102. e.printStackTrace();
  103. }
  104.  
  105. public static String join(List<String> list, String delim) {
  106.  
  107. StringBuilder sb = new StringBuilder();
  108.  
  109. String loopDelim = "";
  110.  
  111. for(String s : list) {
  112.  
  113. sb.append(loopDelim);
  114. sb.append(s);
  115.  
  116. loopDelim = delim;
  117. }
  118.  
  119. return sb.toString();
  120. }
  121.  
  122. protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  123.  
  124. getServletContext().getRequestDispatcher("/select_data.jsp").include(request, response);
  125. PrintWriter out=response.getWriter();
  126.  
  127. response.setContentType("text/html");
  128. String select;
  129. select=request.getParameter("select");
  130.  
  131. try{
  132. Class.forName("oracle.jdbc.driver.OracleDriver");
  133. Statement st = Login.con.createStatement();
  134. System.out.println("Connection established successfully!!");
  135. ResultSet rs = st.executeQuery(select);
  136. ResultSetMetaData rsmd = rs.getMetaData();
  137.  
  138. int columnsNumber = rsmd.getColumnCount();
  139. System.out.println("row:"+columnsNumber);
  140. out.println("<br><table border=1 align="center">");
  141.  
  142. out.println("<tr>");
  143. for(int i=1;i<=columnsNumber;i++){
  144. out.println("<th>"+rsmd.getColumnName(i)+"</th>");
  145. }
  146. out.println("</tr>");
  147.  
  148. while(rs.next()){
  149. out.println("<tr>");
  150. for(int i=1;i<=columnsNumber;i++){
  151. out.println("<td>"+rs.getString(i)+"</td>");
  152. }
  153. out.println("</tr>");
  154.  
  155. }
  156. request.setAttribute("select",select);
  157. out.println("<table>");
  158.  
  159. }catch(Exception e){
  160.  
  161. out.println("<p align="center">"+e.getMessage()+"</p>");
  162. }
  163. }
  164.  
  165.  
  166. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  167.  
  168. }
  169.  
  170.  
  171. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  172.  
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement