64 642
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #9731 in Java | JSP | JSF for ashok

Question #9731
I want to fetch data from database to jsp Page. Whenever we type a word relating words starting with letter typed should be filled automatically by fetching from the DB like a drop down.
Expert's answer

<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>

<HTML>
& lt;HEAD>
lt;TITLE>Fetching Data From a Database</TITLE>
& lt;/HEAD>

& lt;BODY>
lt;H1>Database Lookup</H1>
lt;FORM ACTION="self.jsp" METHOD="POST">
Please enter the ID of the publisher you want to find:
lt;BR>
lt;INPUT TYPE="TEXT" NAME="id">
lt;BR>
lt;INPUT TYPE="SUBMIT" value="Submit">
lt;/FORM>


lt;H1>Fetching Data From a Database</H1>

lt;%
Connection connection = DriverManager.getConnection(
& quot;jdbc:odbc:data", "userName", "password");

Statement statement = connection.createStatement();

String id = request.getParameter("id");&

ResultSet resultset =
statement.executeQuery("select * from tableName where id = '" + id + "'") ;

if(!resultset.next()) {
out.println("Sorry, could not find that publisher. " +
& quot;Please <A HREF='tryAgain.html'>try again</A>.");
} else {
& %>

lt;TABLE BORDER="1">
lt;TR>
lt;TH>ID</TH>
lt;TH>Name</TH>
lt;TH>City</TH>
lt;TH>State</TH>
lt;TH>Country</TH>
lt;/TR>
lt;TR>
lt;TD> <%= resultset.getString(1) %> </TD>
lt;TD> <%= resultset.getString(2) %> </TD>
lt;TD> <%= resultset.getString(3) %> </TD>
lt;TD> <%= resultset.getString(4) %> </TD>
lt;TD> <%= resultset.getString(5) %> </TD>
lt;/TR>
& lt;/TABLE>
& lt;BR>
& lt;%
& }
%>
& lt;/BODY>
</HTML>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions