Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <HTML>
- <HEAD>
- <TITLE>My first JSP-search page! </TITLE>
- <LINK href="../main.css" rel=stylesheet type=text/css>
- </HEAD>
- <BODY>
- <p class=header> Database Web Search</p>
- <FORM method="POST" action="db_search.jsp">
- <table>
- <tr>
- <td class=menu_col> Enter your search string:</td>
- <td class=menu_col><INPUT type="text" name="name" value=''> </td>
- </tr>
- </table>
- <INPUT type="submit" value="Search">
- <INPUT type="Reset" value="Clear">
- </FORM>
- <!--// Importing the packages:-->
- <%@ page import="java.util.*"%>
- <%@ page language="java" import="java.sql.*"%>
- <%
- // Getting the "name" parameter from the form:
- String nachName=request.getParameter("nachName");
- // just a security precaution:
- if (nachName==null) {name="";}
- try
- { // Typical java "try-catch" loop
- // Loading the driver:
- Class.forName("oracle.jdbc.driver.OracleDriver");
- // Creating a connection:
- Connection connection = DriverManager.getConnection
- ("jdbc:oracle:thin:@localhost:1521:orcl", "dblab18", "dblab18");
- // Creating a statement object:
- Statement statement=connection.createStatement();
- // Getting the "ResultSet" Object:
- __________________________________________________________________________
- //-- Prepare the query as a string (just for simplicity):
- //-- Searching all the entries in "FirstName" column,
- // which contain a string, passed from JSP:
- String query ="SELECT vorName FROM Agent WHERE your_column LIKE '%"
- +name+ "%'";
- //-- Execute the query:
- ResultSet result_search=statement.executeQuery(query);
- %>
- __________________________________________________________________________
- <br>
- <font class=bg_row> Search Results: </font>
- <ul>
- <%
- while(result_search.next())
- {
- %>
- <li><%=result_search.getString(1)%>
- <!-- "1" refers to the first column of the result set
- in the result of the first attribute in "SELECT" clause-->
- </li>
- <%
- }
- %>
- </ul>
- <%
- // Closing the ResultSets:
- result_search.close();
- // Closing the Statement object:
- statement.close();
- // Closing the connection:
- connection.close();
- } catch(Exception e){out.println("Error!"+e);}
- //back to HTML :-)
- %>
- </BODY>
- </HTML>
Add Comment
Please, Sign In to add comment