Hi,
I have created the following table in MSAccess & displaying all records on the browser successfully(
jsp file).
TitleAuthor Price
javamurach 400
ckanitkar 350
sqlkevin 450
Now I am calling the particular record of the table through a separate html file, which has 1 textfiled & 1 search button. When I insert the record in the textfield "java" & click on submit button only the "heading tag is displaying. That is
Title Author Price
It is not retrieving any data from the database. Find my jsp code as follows.I think so problem might be with query. Can anybody please help me out.
Thanks in advance.
<html>
<head> <title> an example of a simple model </title></head>
<body>
<center>
<font color = "blue" size ="6">
a listing of books
</font>
</center>
<br><br>
<%@ page import = "java.sql.*"%>
<table width = "100%" border="2" bgcolor="silver">
<tr> <th width = "50%"> Title </th>
<th width = "25%"> Author </th>
<th width = "25%"> Price </th>
</tr>
<%
String subject = request.getParameter("name"); //where name is the value of the textfield of html page.
try {
String query = "SELECT * FROM table1 where Title='subject'";
//table1 is the table name.
System.out.println("before class"); //breakpoint used.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("Jdbc:Odbc:prakashdsn");
System.out.println("after Class");
Statement stmt = con.createStatement();
System.out.println("before query");
ResultSet rs = stmt.executeQuery(query);
System.out.println("after query");
while(rs.next()) {
System.out.println("after result set");
%>
<tr><td><%=rs.getString("Title")%> </td>
<td><%=rs.getString("Author")%> </td>
<td><%=rs.getInt("Price")%> </td>
</tr>
<%
}
%>
</table>
<%
if(stmt!=null)
stmt.close();
if(con!=null)
con.close();
}//end of try block
catch(ClassNotFoundException c) {
System.out.println(c.getMessage());
System.out.println("class not found exception");
}
catch(SQLException s) {
System.out.println(s.getMessage());
System.out.println("sql exception");
}
catch (Exception e)
{
out.print(e.getMessage());
System.out.println("general exception");
}
%>
</body>
</html>