Guest User

Untitled

a guest
May 19th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <HTML>
  2. <HEAD>
  3. <TITLE>My first JSP-search page! </TITLE>
  4. <LINK href="../main.css" rel=stylesheet type=text/css>
  5. </HEAD>
  6. <BODY>
  7. <p class=header> Database Web Search</p>
  8. <FORM method="POST" action="db_search.jsp">
  9. <table>
  10. <tr>
  11. <td class=menu_col> Enter your search string:</td>
  12. <td class=menu_col><INPUT type="text" name="name" value=''> </td>
  13. </tr>
  14. </table>
  15. <INPUT type="submit" value="Search">
  16. <INPUT type="Reset" value="Clear">
  17. </FORM>
  18. <!--// Importing the packages:-->
  19. <%@ page import="java.util.*"%>
  20. <%@ page language="java" import="java.sql.*"%>
  21. <%
  22. // Getting the "name" parameter from the form:
  23. String nachName=request.getParameter("nachName");
  24. // just a security precaution:
  25. if (nachName==null) {name="";}
  26. try
  27. { // Typical java "try-catch" loop
  28. // Loading the driver:
  29. Class.forName("oracle.jdbc.driver.OracleDriver");
  30. // Creating a connection:
  31. Connection connection = DriverManager.getConnection
  32. ("jdbc:oracle:thin:@localhost:1521:orcl", "dblab18", "dblab18");
  33. // Creating a statement object:
  34. Statement statement=connection.createStatement();
  35. // Getting the "ResultSet" Object:
  36.  
  37. __________________________________________________________________________
  38.  
  39. //-- Prepare the query as a string (just for simplicity):
  40. //-- Searching all the entries in "FirstName" column,
  41. // which contain a string, passed from JSP:
  42. String query ="SELECT vorName FROM Agent WHERE your_column LIKE '%"
  43. +name+ "%'";
  44. //-- Execute the query:
  45. ResultSet result_search=statement.executeQuery(query);
  46. %>
  47.  
  48. __________________________________________________________________________
  49.  
  50.  
  51. <br>
  52. <font class=bg_row> Search Results: </font>
  53. <ul>
  54. <%
  55. while(result_search.next())
  56.  
  57. {
  58. %>
  59. <li><%=result_search.getString(1)%>
  60. <!-- "1" refers to the first column of the result set
  61. in the result of the first attribute in "SELECT" clause-->
  62. </li>
  63. <%
  64. }
  65. %>
  66. </ul>
  67. <%
  68. // Closing the ResultSets:
  69. result_search.close();
  70. // Closing the Statement object:
  71. statement.close();
  72. // Closing the connection:
  73. connection.close();
  74. } catch(Exception e){out.println("Error!"+e);}
  75. //back to HTML :-)
  76. %>
  77. </BODY>
  78. </HTML>
Add Comment
Please, Sign In to add comment