Hi Xing,
Thanks a lot for ur kind help.Today I tried to run the program given by
u.But the selected records are not shown .I have added codes in ur
/*
before close the rs, get the records
yourself.
*/
Please check it why it is not working
test2.jsp
<html>
<head>
<title>
Database Search
</title>
</head>
<body background="background8.jpg" bgcolor="#FFFFFF" bgproperties="fixed">
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="db" class="com.wrox.jspexamples.test3" />
<%! ResultSet rs = null;%>
<%! String tablename;%>
<%! int p;%>
<%! int numColumns;
ResultSetMetaData rsmd = null;
%>
<center>
<table border="1" bgcolor="#cccc99" bordercolor="#003366">
<tr>
<%
String sql1 = request.getParameter("D1");
String sql2 = request.getParameter("table");
//add the code yourself to judge whether the sql2 & sql2 is null
or not. ***
try
{
db.connect();
while((p = sql2.indexOf(',')) != -1)
{
tablename = sql2.substring(0, p);
sql2 = sql2.substring(p + 1);
rs = db.execSQL(sql1, tablename);
try {
rsmd = rs.getMetaData();
numColumns = rsmd.getColumnCount();
for (int column = 1; column <= numColumns; column++) {
%>
<th><%= rsmd.getColumnName(column) %></th>
<%
}
%>
</tr>
<%
while (rs.next()) {
%>
<tr>
<%
for (int column = 1; column <= numColumns; column++) {
%>
<td><%= rs.getString(column) %></td>
<% } %>
</tr>
<% }
rs.close();
db.close();
} catch (SQLException e) {
throw new ServletException("Database error. The query worked, " +
"but the display didn't", e);
}
%>
<tr>
<td>
<%= "select * from " + tablename + " where YEAR = " + sql1 %>
</td>
</tr>
<%
}
rs = db.execSQL(sql1, sql2);
/*
before close the rs, get the records yourself.
*/
rs.close();
%>
<tr>
<td>
<%= "select * from " + sql2 + " where YEAR = " + sql1 %>
</td>
</tr>
<%
}
catch (SQLException e)
{
out.println ("\n*** SQLException caught ***\n");
out.println("<br>");
while (e != null)
{
out.println ("SQLState: " + e.getSQLState ());
out.println("<br>");
out.println ("Message: " + e.getMessage ());
out.println("<br>");
out.println ("Vendor: " + e.getErrorCode ());
out.println("<br>");
e = e.getNextException ();
out.println("<br>");
}
}
%>
</table>
</center>
</body>
</html>
Awaiting ur reply
Thanx again
Biren
On Fri, 9 Jun 2000, Xing Guohong wrote:
> Does my example do not work in your side?
>
> xgh
>
> ----- Original Message -----
> From: Biren Patnaik
> To: [EMAIL PROTECTED]
> Sent: Friday, June 09, 2000 07:32 PM
> Subject: Problems in retrieving data from database by selecting multiple
> check boxes
>
>
> Hi,
> I have sent this problem some days ago,but I could not get any
> appropriate answer.I m sending the same problems again.
> > Can anyone please suggest me how to generate data from multiple
> selection
> > of Check Boxes.
> > I m describing my problems as below.
> > I have got one List Boxes.There are 4 items in List Boxes.They are all
> > Numeric.They are 1997,1998,1999,2000 all are values for Year.
> > I have 4 Check Boxes,They are D1,D2,D3,D4.D1 is a column name of table
> > tab1,Like that D2 is a column name of table tab2,like of D3 and D4.
> > year is one of the column name of tab1,tab2,tab3 and tab4 table.
> > My problem is If I select 1997 from List Boxes and select D1,D2,D3 from
> > Check Boxes,I should get records generated from tab1,tab2,tab3 for the
> > year 1997
> > I will appreciate for any kinds of solution.
> > Thanks in advance
> > Biren
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets