Hi Xing,
Thanx for ur kind contribution to my problems.I m sending u the detail
code (HTML,JSP AND JAVA BEANS File).Please check it do some modifications
for geeting the result.My main problem is
How can I pass parameters in ORACLE depending on the selection of Check
boxes
<TEST1.HTML---BEGIN--->
<html>

<head>
<title>TABLE1</title>

</head>

<body>

<form method="POST" action="TEST2.jsp">
  <p><select name="D1" size="4" multiple>
    <option selected value="1996">1996</option>
    <option value="1997">1997</option>
    <option value="1998">1998</option>
    <option value="1999">1999</option>
  </select></p>
<p><input type="checkbox" name="C1" value="ON">TABLE1</p>
<p><input type="checkbox" name="C2" value="ON">TABLE2</p>
</form>
</body>
</html>
<----END TEST1.HTML--->

<---BEGIN 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" scope="request" class="TEST3" />

<jsp:setProperty name="db" property="*" />

<%! int numColumns;
    ResultSet rs = null;
    ResultSetMetaData rsmd = null;
%>

<center>
<h2>Results From Year</h2>
<h2><%= request.getParameter("D1") %></h2>
<hr>
<br><br>
<table border="1" bgcolor="#cccc99" bordercolor="#003366">
<tr>

<%
   String sql1 = request.getParameter("D1");
   String sql2 = request.getParameter("C1");
   String sql3 = request.getParameter("C2");

   try {
      db.connect();
   } catch (ClassNotFoundException e) {
      throw new ServletException("Database drivers not available", e);
   } catch (SQLException e) {
      throw new ServletException("Database URL is wrong", e);
   }

   try {

<----Here is my main problem for passing parameters into java beans
program- How can I pass parameters in ORACLE depending on the selection of
Check boxes ---->


      rs = db.execSQL(sql1,sql2,sql3);
   } catch (SQLException e) {

   }

   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);
   }
%>

</table>
</center>
</body>
</html>
<----END TEST2.JSP---->

<----BEGIN TEST3.JAVA----->
package com.wrox.jspexamples;

import java.sql.*;
import java.io.*;

public class TEST3 {

   String dbURL,action;

   private Connection dbCon;

   public TEST3() {
      super();
   }

   public boolean connect() throws ClassNotFoundException, SQLException {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      dbCon =
DriverManager.getConnection("jdbc:odbc:prjct1","scott","tiger");
      return true;
   }

   public void close() throws SQLException {
      dbCon.close();
   }

   public ResultSet execSQL(String sq1,String sq2) throws SQLException {
      Statement s = dbCon.createStatement();

//Problem arises here how to pass parameters

      ResultSet r = s.executeQuery("SELECT * FROM AOP_SP WHERE SIN_YR =
'"+sq1+"' OR SIN_YR ='"+sq2+"'");
      return (r == null) ? null : r;
   }
public void setAction( String pageAction )
{ action = pageAction; }

public String getAction() { return action; }

   public int getDbDriver() {
      return 0;
   }

   public void setDbDriver(String newValue) {

   }


}


Please answer
Awaiting ur reply
Biren


On Thu, 8 Jun 2000, Xing Guohong wrote:

> Hi Berin, the example I gave last time is just an example. Now I know your
> definite request. I provide the two files to you.
> --file1.jsp begin
> <html>
> <%@ page language="java"%>
> <form name="test" method="post" action="file2.jsp">
> <input type="checkbox" name="test" value="aaa">aaa:
> <input type="checkbox" name="test" value="bbb">bbb:
> <input type="checkbox" name="test" value="ccc">ccc:
> <input type="checkbox" name="test" value="ddd">ddd:
> <input type="submit" name="retrive" value="retrieve">
> </form>
> </html>
> --file1.jsp end
>
> --file2.jsp begin
> <html>
> <%@ page language="java"%>
> <%! String str;%>
> <%
>  str = request.getParameter("test");
> %>
> <%=str%>
> </html>
> --file2.jsp end
>
>     After creating the two files, invoke file1.jsp in your browse and check
> the checkboxes you want, push the retrieve button then you will get the
> result you expect. Analyse the string you get and then access the db
> according to the analysis result. About the accessing to oracle, If you
> want, I will give your another example.
>     Hope this helps. Any question, contact me.
>
> xgh
>
> ----- Original Message -----
> From: Biren Patnaik
> To: [EMAIL PROTECTED]
> Sent: Wednesday, June 07, 2000 11:04 PM
> Subject: Re: How to access data from multiple selection of CheckBoxes
>
>
> Hi xgh,
> Thanx a lot for ur quick reply to my question.But ur solution did not help
> me solving my problem.Can u please send me any examples of accessing data
> from Oracle database by multiple selection of CheckBoxes.How can I retrive
> data from multiple tables by selecting multiple CheckBoxes.How will I pass
> CheckBoxes parameter in my JSP.
> Awaiting ur reply
> Biren
>
>
> On Wed, 7 Jun 2000, Xing Guohong wrote:
>
> > The follow is an example:
> > --begin
> > <html>
> > <%@ page language="java"%>
> > <script language="JavaScript">
> > <!--
> > function display()
> > {
> >  var ftest = document.test;
> >  var len = ftest.elements.length;
> >  var i = 0;
> >  var str = "You chose ";
> >  for(i = 0 ; i < len; i++)
> >  {
> >   if(ftest.elements[i].name == "test")
> >   {
> >    if(ftest.elements[i].checked)
> >    {
> >     str += ftest.elements[i].value;
> >     str += " ";
> >    }
> >   }
> >  }
> >  alert(str);
> > }
> > file://-->
> > </script>
> > <form name="test">
> > <input type="checkbox" name="test" value="aaa">aaa:
> > <input type="checkbox" name="test" value="bbb">bbb:
> > <input type="checkbox" name="test" value="ccc">ccc:
> > <input type="checkbox" name="test" value="ddd">ddd:
> > <input type="button" name="ok" value="test"
> onClick="javascript:display();">
> > </form>
> > </html>
> > --end
> >
> > If you submit the page to another page that get the checkbox info, try
> > request.getParameter("test") in that page.
> >
> > xgh
> >
> >
> >
> > ----- Original Message -----
> > From: Biren Patnaik
> > To: [EMAIL PROTECTED]
> > Sent: Wednesday, June 07, 2000 08:06 PM
> > Subject: How to access data from multiple selection of CheckBoxes
> >
> >
> > Hi,
> > 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

Reply via email to