index.jsp
Database Lookup
Database Lookup
basic.jsp
<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>
Fetching Data From a Database
Fetching Data From a Database
<%
Connection connection = DriverManager.getConnection(
"jdbc:odbc:data", "YourName", "password");
Statement statement = connection.createStatement();
String id = request.getParameter("id");
ResultSet resultset =
statement.executeQuery("select * from Publishers where pub_id = '" + id + "'") ;
if(!resultset.next()) {
out.println("Sorry, could not find that publisher. ");
} else {
%>
ID
Name
City
State
Country
<%= resultset.getString(1) %>
<%= resultset.getString(2) %>
<%= resultset.getString(3) %>
<%= resultset.getString(4) %>
<%= resultset.getString(5) %>
<%
}
%>