Retrieve values from database

Hi,
one of the search form contains the select option for country , state and
distributor type.
the country drop down has 2 values - US and canada
the conditions needed to be satisfied are :
(1) if the country selected is US - then the states dropdown should only show the states that are associated with US in the table in the database(TABLE name is - "distributors")
and if country selected is Canada - then should show states in canada only
(2) if canada is selected in the country dropdown, the distributor type which has 2 values - stationary and automotive - should show only the stationary in the dropdown and not show the automotive
This is done with the LocateQueryServlet.java...can someone please tell me how this needs to be updates so that the above conditions are satisfied...
Attaching the code from LocateQueryServlet.java and the prolog.sql
--------------------------------------------------------------------------------------------------LocateQueryServlet.java
package com.dupont.refrigerants.distributorlocator;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.ejb.CreateException;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.proxicom.util.MiscEJBFunctions;
* This servlet displays a query form for locating distributors. It relies on
* the 'countries', 'states' and 'types' tables in the database to fill its
* forms. If a table is empty, it doesn't display the corresponding select
* (pulldown) widget. This only displays the form fragment of HTML, and should
* be included in a complete page, probably with JSP or the like.
* XXX Currently, the form is populated when the servlet is initialized, which
* is a hack because I don't remember the appropriate j2ee idiom.
* @web.servlet name="queryServlet" display-name="Distributor Locator Query
* Servlet" description="Servlet that gets a query form for finding
* distributors in a given region"
* @web.servlet-mapping url-pattern="/queryServlet"
public class LocateQueryServlet extends HttpServlet {
     * Abstract class for converting a java object into
     * an option element for an HTML select form widget.
     private abstract static class Object2Option {
          * Gets the default option at the top of the select.
          * To have no default, override this to return the
          * empty string.
          * @return <code>>option selected='true' value=''<-- Select One -->/option<</code>
          public String getDefault() {
               return "<option selected='true' value=''>-- Select One --</option>";
          * The option element that represents the given info object.
          * @param o the info object
          * @return an unselected HTML option element.
          abstract public String getOptionFor(Object o);
          * Helper method for generating a select option element
          * with the given un-encoded value and text.
          * @param value
          * unencoded string to be passed as the form
          * value when selected
          * @param text
          * unencoded string to be displayed in the select
          * box pulldown
          * @return the concatenated and appropriately escaped
          * option element
          protected static String getOptionWith(String value, String text) {
               return "<option value='" + Utilities.webify(value, false) + "'>"
                         + Utilities.webify(text, false) + "</option>";
     * Function object for generating 'Country' select box items.
     private static class Object2CountryOption extends Object2Option {
          * Converts a CountryInformation object into an appropriate
          * HTML option element.
          public String getOptionFor(Object o) {
               CountryInformation c = (CountryInformation) o;
               return getOptionWith(c.getCode(), c.getName());
     * Function object for generating 'Distributor Type' select box items.
     private static class Object2DistributorTypeOption extends Object2Option {
          * Converts a DistributorTypeInformation object into an appropriate
          * HTML option element.
          public String getOptionFor(Object o) {
               DistributorTypeInformation c = (DistributorTypeInformation) o;
               return getOptionWith(String.valueOf(c.getId()), c.getDescription());
     * Function object for generating 'State/Province' select box items.
     private static class Object2StateOption extends Object2Option {
          * Converts a StateInformation object into an appropriate
          * HTML option element.
          public String getOptionFor(Object o) {
               StateInformation c = (StateInformation) o;
               return getOptionWith(c.getCode(), c.getName());
     private String countries;
     private String states;
     private String types;
     * Constructs a simple locate query servlet.
     public LocateQueryServlet() {
          super();
     * Generates an HTML select form widget for the given list of values.
     * @param formName the name of the widget for the HTML name attribute
     * @param values the values to convert into a list
     * @param factory the method for converting each value into an option.
     * @return the complete 'select' element
     private String generateSelectFor(String formName, List values,
               Object2Option factory) {
          StringBuffer sb = new StringBuffer();
          sb.append("<select name='").append(Utilities.webify(formName, false)).append("'>");
          sb.append(factory.getDefault());
          for (Iterator iter = values.iterator(); iter.hasNext();) {
               sb.append(factory.getOptionFor(iter.next()));
          sb.append("</select>");
          return sb.toString();
     * Initializes the servlet. Actually results in some queries getting run.
     * @param config
     * @throws ServletException
     public void init(ServletConfig config) throws ServletException {
          try {
               DistributorDBABeanHome distBean = (DistributorDBABeanHome) MiscEJBFunctions.getBeanHomeInterface(null, null, Utilities.EJB_DISTRIBUTOR_DBA_NAME);
               DistributorDBABean dists = distBean.create();
               this.countries = this.generateSelectFor("country", dists.getCountries(),
                         new Object2CountryOption());
               this.states = this.generateSelectFor("state", dists.getStates(),
                         new Object2StateOption());
               this.types = this.generateSelectFor("type", dists.getDistributorTypes(),
                         new Object2DistributorTypeOption());
          } catch (NamingException e) {
               throw new ServletException("Lookup of "
                         + Utilities.EJB_DISTRIBUTOR_DBA_NAME + " failed", e);
          } catch (CreateException e) {
               throw new ServletException(
                         "Error while creating distributor session bean", e);
          } catch (java.rmi.RemoteException e) {
               throw new ServletException(
                         "Error while initializing distributor locator", e);
     * Executes the HTTP request and return the appropriate HTML form fragment.
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     protected void doGet(HttpServletRequest request,
               HttpServletResponse response) throws ServletException, IOException {
          PrintWriter out = response.getWriter();
          response.setContentType("text/html");
          String action = request.getParameter("action");
          if (action == null) {
               action = "where-to-buy-results";
          } else {
               action = Utilities.webify(action, false);
          // Open form and table elements.
          out.println("<form id='distributorLocator' action='" + action + "' method='get'>"
                              + "<table width='100%' border='0' cellpadding='4' cellspacing='0'>");
          // buffer row
          //out.println("<tr><td colspan='2'><hr width='65%' size='1' noshade></td></tr>");
          // 'Country' row
          out.println("<tr><td><div align='right' class='formSubHead'>Country:</div></td>"
                              + "<td>" + this.countries + "</td></tr>");
          // 'States' row
          out.println("<tr><td><div align='right' class='formSubHead'>State/Province:</div></td>"
                              + "<td>" + this.states + "</td></tr>");
          // 'Application' row
          out.println("<tr><td><div align='right' class='formSubHead'>Application:</div></td>");
          out.println("<td>" + this.types + "</td></tr>");
          // or row
          out.println("<tr><td><div align='right'></div></td><td><em><strong>or</strong></em></td></tr>");
          // zip code row
          out.println("<tr><td><div align='right' class='formSubHead'>Zip Code/Postal Code: </div></td>"
                              + "<td><input id='zip' name='zip' type='text' /></td></tr>");
          // buffer row
          out.println("<tr><td colspan='2'><hr width='65%' size='1' noshade></td></tr>");
          // submit row
          out.println("<tr><td> </td><td><input type='submit' value='Find' /></td></tr>");
          // end table and form
          out.println("</table></form>");
prolog.sql
SET DEFINE OFF;
CREATE SEQUENCE distributor_id_seq START WITH 1 INCREMENT BY 1 NOMAXVALUE;
CREATE TABLE countries (code CHAR(2), name VARCHAR(254),
     CONSTRAINT country_pk PRIMARY KEY(code));
CREATE TABLE states (code CHAR(5), name VARCHAR(254), country CHAR(2),
     CONSTRAINT state_pk PRIMARY KEY(code),
     CONSTRAINT fk_country FOREIGN KEY(country) REFERENCES countries(code));
CREATE TABLE distributorTypes (id INTEGER, name VARCHAR(254),
     CONSTRAINT distributorType_pk PRIMARY KEY(id));
CREATE TABLE distributors
     (id INTEGER,
     name VARCHAR(254),
     zip VARCHAR(12),
     country CHAR(2),
     state CHAR(5),
     city VARCHAR(63),
     address1 VARCHAR(254),
     address2 VARCHAR(254),
     fax VARCHAR(32),
     phone VARCHAR(32),
     managers VARCHAR(254),
     type INTEGER,
     email VARCHAR(254),
     url VARCHAR(254),
     CONSTRAINT distributor_pk PRIMARY KEY(id),
     CONSTRAINT fk_dist_country FOREIGN KEY(country) REFERENCES countries(code),
     CONSTRAINT fk_dist_state FOREIGN KEY(state) REFERENCES states(code),
     CONSTRAINT fk_dist_type FOREIGN KEY(type) REFERENCES distributorTypes(id));
CREATE TABLE statesApply (state CHAR(5), distributor INTEGER,
     CONSTRAINT fk_apply_state FOREIGN KEY(state) REFERENCES states(code),
     CONSTRAINT fk_apply_distributor FOREIGN KEY(distributor) REFERENCES distributors(id));
INSERT INTO
          distributorTypes (id, name) VALUES (1, 'Air Conditioning - Stationary and Refrigeration');
INSERT INTO
          distributorTypes (id, name) VALUES (2, 'Air Conditioning - Automotive');
INSERT INTO
          countries (code, name) VALUES ('CA', 'Canada');
INSERT INTO
          countries (code, name) VALUES ('US', 'United States of America');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_AL', 'Alabama');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_KS', 'Kansas');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_ND', 'North Dakota');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_AK', 'Alaska');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_KY', 'Kentucky');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MP', 'N. Mariana Islands');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_AS', 'American Samoa');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_LA', 'Louisiana');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_OH', 'Ohio');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_AZ', 'Arizona');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_ME', 'Maine');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_OK', 'Oklahoma');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_AR', 'Arkansas');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MH', 'Marshall Islands');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_OR', 'Oregon');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_CA', 'California');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MD', 'Maryland');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_PW', 'Palau');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_CO', 'Colorado');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MA', 'Massachusetts');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_PA', 'Pennsylvania');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_CT', 'Connecticut');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MI', 'Michigan');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_PR', 'Puerto Rico');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_DE', 'Deleware');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MN', 'Minnesota');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_RI', 'Rhode Island');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_DC', 'District of Columbia');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MS', 'Mississippi');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_SC', 'South Carolina');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_FM', 'FS Micronesia');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MO', 'Missouri');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_SD', 'South Dakota');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_FL', 'Florida');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_MT', 'Montana');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_TN', 'Tennessee');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_GA', 'Georgia');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_NE', 'Nebraska');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_TX', 'Texas');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_GU', 'Guam');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_NV', 'Nevada');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_UT', 'Utah');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_HI', 'Hawaii');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_NH', 'New Hampshire');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_VT', 'Vermont');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_ID', 'Idaho');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_NJ', 'New Jersey');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_VI', 'Virgin Islands');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_IL', 'Illinois');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_NM', 'New Mexico');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_VA', 'Virginia');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_IN', 'Indiana');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_NY', 'New York');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_WA', 'Washington');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_IA', 'Iowa');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_NC', 'North Carolina');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_WV', 'West Virginia');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_WI', 'Wisconsin');
INSERT INTO
          states (country, code, name) VALUES ('US', 'US_WY', 'Wyoming');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_AB', 'Alberta');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_BC', 'British Columbia');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_MB', 'Manitoba');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_NB', 'New Brunswick');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_NL', 'Newfoundland and Labrador');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_NS', 'Nova Scotia');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_NT', 'Northwest Territories');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_NU', 'Nunavut');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_ON', 'Ontario');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_PE', 'Prince Edward Island');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_QC', 'Qu�bec');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_SK', 'Saskatchewan');
INSERT INTO
          states (country, code, name) VALUES ('CA', 'CA_YT', 'Yukon');
Any immediate help is truly appreciated.
Thanks in advance

I thank you for the link, it's something I've already done several times ....
actually this code tries to manage a key incremental, I am obliged to do that because I am in MS SQL Server and therefore what works for oracle does not work for SQL Server, which is why I want to do it manual, I also posted this in a previous post and I was asked to retrieve the field value by Code: Help please : dbsequence refresh on MS sql server
now admitting that it is not what I want to do and I have the following code:
if (it1.getValue () == null) (
Connection connection = ConnectionManager.getInstance (). GetConnection ();
Statement statement = connection.createStatement ();
ResultSet resultset = statement.executeQuery ("SELECT id FROM WHERE name = spider" it2.getValue + () + "");
while (resultSet.next ())
it1.setValue (resultSet.getInt (1));
BindingContainer getBindings bindings = ();
OperationBinding operationBinding bindings.getOperationBinding = ("Commit");
OperationBinding.execute Object result = ();
if (! operationBinding.getErrors (). isEmpty ()) (
return null;
else (
BindingContainer bindings2 getBindings = ();
OperationBinding operationBinding2 bindings2.getOperationBinding = ("Commit");
OperationBinding2.execute Object result = ();
if (! operationBinding2.getErrors (). isEmpty ()) (
return null;
What code ADF BC I will put in place of jdbc code

Similar Messages

  • Retrieving values from Database in Excel Task Pane App

    So far,
    I created a website with a database on Azure, I then published my App to Azure. My problem is that I'm not sure how I retrieve values from the database (in SQL: SELECT * FROM EXAMPLE_TABLE WHERE date = str). If someone could provide me with sample code,
    that would be amazing! :D
    It would also be very helpful if anyone knew a method to automatically update the database using information from a xml stream on another website, once a day.
    Thank you!

    Hi,
    >> My problem is that I'm not sure how I retrieve values from the database
    You can use jquery ajax call to call your webserivce or REST API, which will query the database and return a json result.
    Sample:
    Apps for Office: Create a web service using the ASP.NET Web API
    >> It would also be very helpful if anyone knew a method to automatically update the database using information from a xml stream on another website
    For the database sync-up question, I suggest you posting them on the forums like SQL Server Forum.
    Thanks for your understanding.
    Best Regards
    Lan
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to display checkbox that retrieve value from database?

    Hi,
    I have a problem, hope someone will help me.
    The problem is, I have 3 checkbox where contain different values.
    I will insert the values to db in array. When I retrieve the values, I got a problem to display it.
    Let say,my checkbox's value is:
    1.car
    2.bus
    3.lorry
    when I checked car and lorry, my array will be [car,bus] insert to db.
    For editing purpose, I need to display the checkbox again with the values from db. So, it should be :
    1.car (checked)
    2.bus (checked)
    3.lorry (unchecked)
    I can display the car and bus (checked) , but not the unchecked checkbox. Sometimes, it's repeating, car (checked) and car (unchecked) will display.
    Anybody have a suggestion?
    My codes:
    String[] list = {"car","bus","lorry"};
    String[] logtype ={"car","bus"}//retrieve from db (example)
    for (int i=0;i<logtype.length;i++){
    if (logtype.equals(list[i]){
    <input type="checkbox" name="type" value="<%=list[i]%>" checked>
    else{
    <input type="checkbox" name="type" value="<%=list[i]%>" >

    hey u can solve this problem by using vector instead of array
    here's the code
    <%
    Vector list=new Vector();
    list.addElement("car");
    list.addElement("bus");
    list.addElement("lorry");
    Vector logtype=new Vector();
    logtype.addElement("car");
    logtype.addElement("bus");
    for(int i=0;i<list.size();i++)
         if(logtype.contains(list.elementAt(i)))
         { %>
              <%=list.elementAt(i)%><input type="checkbox" name="type" value="<%=list.elementAt(i)%>" checked>
         <%}
         else
         {%>
              <%=list.elementAt(i)%><input type="checkbox" name="type" value="<%=list.elementAt(i)%>" >
         <%}
    %>

  • Retriev values from database and display in a ComboBox

    hi all,
    i think the subject explains it all. how? currently iam using vectors which is giving me lots of problems and errors, whenever it adds to the combobox it adds the square braces as well example if the value in database is asrar then it will display [asrar], what is causing that? does anybody now any easier way??
    asrar

    please can someone help me
    asrar

  • Retrieving values from a table

    Hi all,
    I need to retrieve values from CSKS-KOSTL for values containing the pattern entered by the user. For example, if the user enters 1, need to retrieve all the KOSTL values starting with 1. But when i write a SELECT statement mentioning where kostl in '1', it is ignoring all the values like (0000001, 00001034, 0012334, and others). Only values starting with 1 is only retrieved as this is a character field and due to conversion routine, zeroes are prefixed while storing in the database.
    Could any one let me know how to retrieve the values from the database in this situation?

    If you want to use IN operator in your where clause then you should define a range variable(R_KOSTL) which refers to CSKS=KOSTL and populate the range as below
    R_KOSTL-SIGN = 'I'.
    R_KOSTL-OPTION = 'CP'.
    R_KOSTL-LOW = '1*'.
    APPEND R_KOSTL.
    and then write your select statement as .... WHERE kostl IN r_kostl.
    The approach suggested by Amit should also work fine.
    Thanks
    Kiran

  • List of values from Database Adapter - BPM Forms

    Hi all,
    Can anyone tell me how to get list of values from Database adapter and a ServiceTask.
    As example lets say a table has Employee and Department columns.
    I want to list down all the Employees in BPM form (Select One List Box) once i provide the department to the Database Adapter.
    Is it possible from the DB Adapter?? What will be the variable type?
    Thanks,
    Nir

    Hi DanielAtwood,
    Thanks for your reply...
    Actually when i send the variable in 'WHERE Clause' in Db Adapter query it will retrieve more than one record as the output.
    I want to put that values to a 'SelectOneChoice' component and list down all the values..
    First I tried with data control. But i couldn't find the way to pass the value to the variable(in WHERE clause) to the query in data control view.
    Thanks,
    Nir

  • Try to retrieve data from database got error message

    Try to retrieve data from database got error message *"java.lang.ArrayIndexOutOfBoundsException: 2*
    *     sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(JdbcOdbcPreparedStatement.java:1023)*
    *     sun.jdbc.odbc.JdbcOdbcPreparedStatement.setDate(JdbcOdbcPreparedStatement.java:811)*
    *     guestbk.doGet(guestbk.java:32)*
    *     guestbk.doPost(guestbk.java:73)*
    *     javax.servlet.http.HttpServlet.service(HttpServlet.java:710)*
    *     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)"*
    I have used prepared statment
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yy");
                java.util.Date dt = sdf.parse(str3);
                       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                       con=DriverManager.getConnection("jdbc:odbc:gbook");
                       //Statement stmt=con.createStatement();
    PreparedStatement ps = con.prepareStatement("SELECT * from gbook where emailid =? AND date =?");
    ps.setString(1,str1);
    ps.setString(2,str2);
    ps.setDate(3,new java.sql.Date(dt.getTime()));
    //ps.executeQuery();
                       //ResultSet rs=stmt.executeQuery("select * from gbook where emailid = str1");
                  ResultSet rs = ps.executeQuery();
                       out.println("<Html>");
                    out.println("<Head>");
                       out.println("<Title>GuestBook</Title>");
                       out.println("</Head>");
                       out.println("<Table border=1 align=center >");
                       out.println("<H4><B><center>Teacher's Lesson Plan</center></B></H4><BR>");
                       out.println("<TR><TD><b>Teacher Name</b></TD><TD><b>Class</b></TD></TR>");
               while(rs.next())
                        ctr++;
                        String email=rs.getString("emailid");
                        String cmt=rs.getString("comment");
                        out.println("<TR><TD>"+email+"</TD><TD>"+cmt+"</TD></TR>");
            }Please anybody help .

    PreparedStatement ps = con.prepareStatement("SELECT * from gbook where emailid =? AND date =?");
    ps.setString(1,str1);
    ps.setString(2,str2);
    ps.setDate(3,new java.sql.Date(dt.getTime()));Your SQL query has 2 placeholders but you try to set 3 values.
    And didn't you read the stack trace?
    guestbk.doGet(guestbk.java:32)You could've tracked down line 32 and seen what was there at that line.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
    ----------------------------------------------------------------

  • Get username from session and retrieve records from database wit tat userna

    hello..
    i got a ChangePassword.jsp which i retrieve the username from session using bean to display on e page..
    <jsp:getProperty name="UsernamePassword" property = "username"/>
    but in my servlet, i wan to retrieve records from database with tat username..
    i tot of coding
    String username = (String)request.getSession().getAttribute("UsernamePassword");
    and then use tat username to retrieve records.. but is that e right way? The page did not display and i got a CastingException..
    Please help.

    If you are using the session inside a jsp, you can say "session" without having to declare it.String usernamePassword = (String) session.getAttribute("usernamePassword");However, right after you get this value, check if it is null:
    if(usernamePassword==null)
    // do sth like forward to error page
    else
    // continue processing
    If it is null, then you are probably not setting it right in the first place. Make sure that in your servlet A you create a session, and before you return or forward to a jsp, that you actually set this value in the session like saying
    session.setAttribute("usernamePassword", usernamePassword);
    and it is case sensitive for the key.

  • Returning sql statement instead of values from database

    hi am reading value from database but my problem is am get sql statement values instead of values in database
    my code is
    java:337)

    There is no doubt: you get what you want:
        return s_getValue;
    bye
    TPD

  • Unable to access values from database in login page..

    Hey all,
    Friends I have a login.jsp page and I want if i enter username and password then it will be accessed from database and after verifying the details it will open main.jsp.I made a database as "abc" and created DSN as 1st_login having table 1st_login. But the problem is that I am unable to access values from database.
    So Please help me.
    Following is my code:
    <HTML>
    <body background="a.jpg">
    <marquee>
                        <CENTER><font size="5" face="times" color="#993300"><b>Welcome to the"<U><I>XYZ</I></U>" of ABC</font></b></CENTER></marquee>
              <br>
              <br>
              <br>
              <br><br>
              <br>
         <form name="login_form">
              <CENTER><font size="4" face="times new roman">
    Username          
              <input name="username" type="text" class="inputbox" alt="username" size="20"  />
              <br>
         <br>
              Password          
              <input type="password" name="pwd" class="inputbox" size="20" alt="password" />
              <br/>
              <input type="hidden" name="option" value="login" />
              <br>
              <input type="SUBMIT" name="SUBMIT" class="button" value="Submit" onClick="return check();"> </CENTER>
              </td>
         </tr>
         <tr>
              <td>
              </form>
              </table>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connection = DriverManager.getConnection("jdbc:odbc:1st_login");
    Statement statement = connection.createStatement();
    String query = "SELECT username, password FROM 1st_login WHERE username='";
    query += request.getParameter("username") + "' AND password='";
    query += request.getParameter("password") + "';";
    ResultSet resSum = statement.executeQuery(query);
    //change: you gotta move the pointer to the first row of the result set.
    resSum.next();
    if (request.getParameter("username").equalsIgnoreCase(resSum.getString("username")) && request.getParameter("password").equalsIgnoreCase(resSum.getString("password")))
    %>
    //now it must connected to next page..
    <%
    else
    %>
    <h2>You better check your username and password!</h2>
    <%
    }catch (SQLException ex ){
    System.err.println( ex);
    }catch (Exception er){
    er.printStackTrace();
    %>
    <input type="hidden" name="op2" value="login" />
         <input type="hidden" name="lang" value="english" />
         <input type="hidden" name="return" value="/" />
         <input type="hidden" name="message" value="0" />
         <br>
              <br><br>
              <br><br>
              <br><br><br><br><br>
              <font size="2" face="arial" color="#993300">
         <p align="center"> <B>ABC &copy; PQR</B>
    </BODY>
    </HTML>
    and in this code i am getting following error
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:93: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:93: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:94: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:95: cannot find symbol_
    4 errors
    C:\Project\SRS\nbproject\build-impl.xml:360: The following error occurred while executing this line:
    C:\Project\SRS\nbproject\build-impl.xml:142: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 6 seconds)

    As long as you're unable to compile Java code, please use the 'New to Java' forum. This is really trival.
    To ease writing, debugging and maintenance, I highly recommend you to write Java code in Java classes rather than JSP files. Start learning Servlets.

  • How to get string value from database table using Visual Studio 2005?

    Hi,
    Im developing plugin in illustrator cs3 using visual studio 2005. I need to get the values eneterd in database. Im able to get the integer values. But while getting string values it is returning empty value.
    Im using the below code to get the values from database table
    bool Table::Get(char* FieldName,int& FieldValue)
        try
            _variant_t  vtValue;
            vtValue = m_Rec->Fields->GetItem(FieldName)->GetValue();
            FieldValue=vtValue.intVal;
        CATCHERRGET
        sprintf(m_ErrStr,"Success");
        return 1;
    Im using the below code to get the values.
    AIErr getProjects()
        char buf[5000];
        int i;   
        std::string  catName;
        ::CoInitialize(NULL);
        Database db;
        Table tbl;
        errno_t err;
        err = fopen(&file,"c:\\DBResult.txt","w");
        fprintf(file, "Before Connection Established\n");
        //MessageBox(NULL,CnnStr,"Connection String",0);
        if(!db.Open(g->username,g->password,CnnStr))
            db.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
        fprintf(file, "After Connection Established\n");
    if(!db.Execute("select ProjectID,ProjectName from projectsample",tbl))
            db.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
        int ProjectID;
        int UserID;
        int ProjectTitle;
        char ProjectName[ProjectNameSize];
        if(!tbl.ISEOF())
            tbl.MoveFirst();
        ProjectArrCnt=0;
        for(i=0;i<128;i++)
            buf[i]='\0';
            int j=0;
        while(!tbl.ISEOF())
            if(tbl.Get("ProjectID",ProjectID))
                fprintf(file,"Project ID: %d ",ProjectID);
                ProjectInfo[ProjectArrCnt].ProjectID = ProjectID;
                sprintf(buf,"%d",ProjectID);
                //MessageBox(NULL, buf,"f ID", 0);
                j++;
            else
                tbl.GetErrorErrStr(ErrStr);
                fprintf(file,"Error: %s\n",ErrStr);
                break;
            //if(tbl.Get("ProjectTitle",ProjectName))
            if(tbl.Get("ProjectName",ProjectName))
                MessageBox(NULL,"Inside","",0);
                fprintf(file,"ProjectTitle: %s\n",ProjectName);
                //catName=CategoryName;
                ProjectInfo[ProjectArrCnt].ProjectName=ProjectName;
                //sprintf(buf,"%s",ProjectName);
                MessageBox(NULL,(LPCSTR)ProjectName,"",0);
            else
                tbl.GetErrorErrStr(ErrStr);
                fprintf(file,"Error: %s\n",ErrStr);
                break;
            ProjectArrCnt++;
            //MessageBox(NULL, "While", "WIN API Test",0);
            tbl.MoveNext();
        //MessageBox(NULL, ProjectInfo[i].ProjectName.c_str(),"f Name", 0);
        ::CoUninitialize();
        //sprintf(buf,"%s",file);
        //MessageBox(NULL,buf,"File",0);
        fprintf(file, "Connection closed\n");
        fclose(file);
        for(i=0;i<ProjectArrCnt;i++)
            sprintf(buf,"%i",ProjectInfo[i].ProjectID);
            //MessageBox(NULL,buf,"Proj ID",0);
            //MessageBox(NULL,ProjectInfo[i].ProjectName.c_str(),"Project Name",0);
        return 0;
    In the above code im geeting project D which is an integer value. But not able to get the project name.
    Please some one guide me.

    As I said in the other thread, this really isn't the place to ask questions about a database API unrelated to the Illustrator SDK. You're far more like to find people familliar with your problem on a forum that is dedicated to answering those kinds of questions instead.

  • Retrieve values from a HTML table !!!

    Hi.
    How can i retrieve values from a HTML table using javascript ?
    I´m trying to use the command "document.getElementsByTagName" without success.
    Thanks in advance.
    Eduardo

    Hi, Deepu.
    I´m still with trouble in retrieving the value in HTML.
    In debug the C_CELL_ID seems to be correctly updated but
    when using the command "document.getElementById" the value is always "null".
    I implemented in the method DATA_CELL the code :
      if i_x = 3 and i_y = 2.
      C_CELL_ID             = 'zs'.
      C_CELL_CONTENT = 10. 
      endif.
    And in HTML :
    var ztest = document.getElementById('zs');
    alert(ztest);
    Could you help me please.
    Many regards
    Eduardo S.
    Message was edited by: Eduardo   Silberberg

  • How can i get the random values from database?

    Hi,
    i want to get random values from database.
    I try my best find no solution
    plz give solution in either sql query or java method.
    thanks in advance.

    try this:
    Give a numeric row-id to each row of database.
    say (1-100) for 100 rows
    In the program use random function to get random number between 0 and 1. this value u multiply with 100(or total number of rows) and take integer value of it . u then perform sql query to select the a row which matches randomly genarated value with row-id assigned to each row of database
    madhu

  • Fetching values from database into a drop down box

    in my JSP page there are 3 drop down boxes for date of birth......
    what i need is i want to get the values from database into that drop down box when i access the JSP page.......
    session is there....'m getting all other values.......
    I will attach the JSP page.....
    Please help me...........
    Thanks in Advance......
    <%@ taglib uri='/WEB-INF/taglib/struts-bean.tld' prefix='bean'%>
    <%@ taglib uri='/WEB-INF/taglib/struts-logic.tld' prefix='logic'%>
    <%@ taglib uri='/WEB-INF/taglib/dyna.tld' prefix='dyna'%>
    <%@ taglib uri='/WEB-INF/taglib/struts-html.tld' prefix='html'%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title><bean:message key="page_title"/></title>
    <link href="<bean:message key="context"/>/CSS/default.css" rel="stylesheet" type="text/css" />
    <script src="<bean:message key="context"/>/js/AC_RunActiveContent.js" type="text/javascript"></script>
    <link href="<bean:message key="context"/>/CSS/screen.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <%!
    Membership mShip = null;
    %>
    <script language="javascript" >
    function checkDate(Form){
    var d;
    d = Form.year.value+"-"+Form.month.value+"-"+Form.day.value;
    alert("Date is:"+d);
    Form.dob.value = d;
    </script>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>
         <jsp:include flush="true" page="../templates/header.jsp"/>     </td>
    </tr>
    <tr>
    <td class="menuTD">     
         <jsp:include flush="true" page="../templates/menu.jsp"/>     </td>
    </tr>
    <tr>
    <td class="sub_menuTR"> </td>
    </tr>
    <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td class="column" valign="top" width="170"><jsp:include flush="true" page="../templates/left_panel.jsp"/></td>
    <td valign="top" align="left">
              <dyna:message error="error" warning="warning" message="message"/>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="80%" valign="top" align="left">
                   <%
                   if(session != null){
                   mShip = (Membership)session.getAttribute("member");
                   %>
                        <form action="updateContactDetails.dy" method="post" name="form1">
                        <input type="hidden" name="m" value="<%=request.getParameter("m")%>" />
                             <table width="100%" border="0">
                             <tr>
                                  <td>First Name</td>
                                  <td><input name="first_name" type="text" id= "first_name" value = "<bean:write name = "member" property = "first_name" />" /></td>
                             </tr>
                             <tr>
                                  <td>Last Name </td>
                                  <td><input name="last_name" type="text" id="last_name" value = "<bean:write name = "member" property = "last_name" />" > </td>
                             </tr>
                             <tr>
                                  <td>Address</td>
                                  <td><input name="address1" type="text" id="address1" value = "<bean:write name = "member" property = "address1" />" ></td>
                             </tr>
                             <tr>
                                  <td> </td>
                                  <td><input name="address2" type="text" id="address2" value = "<bean:write name = "member" property = "address2" />" ></td>
                             </tr>
                             <tr>
                                  <td>Suburb/City </td>
                                  <td><input name="city" type="text" id="city" value= "<bean:write name = "member" property = "city" />" ></td>
                             </tr>
                             <tr>
                                  <td>State/Territory</td>
                                  <td><input type="text" name="state" value = "<bean:write name = "member" property = "state" />" ></td>
                             </tr>
                             <tr>
                                  <td>Postcode</td>
                                  <td><input type="text" name="postcode" value = "<bean:write name = "member" property = "postcode" />" ></td>
                             </tr>
                             <tr>
                                  <td>Contact Phone</td>
                                  <td><input type="text" name="home_phone" value = "<bean:write name = "member" property = "home_phone" />" ></td>
                             </tr>
                             <tr>
                                  <td>Mobile</td>
                                  <td><input type="text" name="mobile" value = "<bean:write name = "member" property = "mobile" />" ></td>
                             </tr>
                             <tr>
                                  <td>Date of birth</td>
                                  <td nowrap="nowrap"><select name="day">
    <option>Day</option>
    <option value="01">1</option>
    <option value="02">2</option>
    <option value="03">3</option>
    <option value="04">4</option>
    <option value="05">5</option>
    <option value="06">6</option>
    <option value="07">7</option>
    <option value="08">8</option>
    <option value="09">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
                                  <select name="month">
                                       <option>Month</option>
                                       <option value="01">January</option>
                                       <option value="02">February</option>
                                       <option value="03">March</option>
                                       <option value="04">April</option>
                                       <option value="05">May</option>
                                       <option value="06">June</option>
                                       <option value="07">July</option>
                                       <option value="08">August</option>
                                       <option value="09">September</option>
                                       <option value="10">October</option>
                                       <option value="11">November</option>
                                       <option value="12">Decembber</option>
                                  </select>
                                       <select name="year" onChange = "checkDate(this.form);" >
                                       <option>Year</option>
                                       <option value="1957">1957</option>
                                       <option value="1956">1956</option>
                                       <option value="1955">1955</option>
                                       <option value="1954">1954</option>
                                       <option value="1955">1955</option>
                                       <option value="1956">1956</option>
                                       <option value="1957">1957</option>
                                       <option value="1958">1958</option>
                                       <option value="1959">1959</option>
                                       <option value="1960">1960</option>
                                       <option value="1961">1961</option>
                                       <option value="1962">1962</option>
                                       <option value="1963">1963</option>
                                       <option value="1964">1964</option>
                                       <option value="1965">1965</option>
                                       <option value="1966">1966</option>
                                       <option value="1967">1967</option>
                                       <option value="1968">1968</option>
                                       <option value="1969">1969</option>
                                       <option value="1970">1970</option>
                                       <option value="1971">1971</option>
                                       <option value="1972">1972</option>
                                       <option value="1973">1973</option>
                                       <option value="1974">1974</option>
                                       <option value="1975">1975</option>
                                       <option value="1976">1976</option>
                                       <option value="1977">1977</option>
                                       <option value="1978">1978</option>
                                       <option value="1979">1979</option>
                                       <option value="1980">1980</option>
                                       <option value="1981">1981</option>
                                       <option value="1982">1982</option>
                                       <option value="1983">1983</option>
                                       <option value="1984">1984</option>
                                       <option value="1985">1985</option>
                                       <option value="1986">1986</option>
                                       <option value="1987">1987</option>
                                       <option value="1988">1988</option>
                                       <option value="1989">1989</option>
                                       <option value="1990">1990</option>
                                       <option value="1991">1991</option>
                                       <option value="1992">1992</option>
                                       <option value="1993">1993</option>
                                       <option value="1994">1994</option>
                                       <option value="1995">1995</option>
                                       <option value="1996">1996</option>
                                       <option value="1997">1997</option>
                                       <option value="1998">1998</option>
                                       <option value="1999">1999</option>
                                       <option value="2000">2000</option>
                                       <option value="2001">2001</option>
                                       <option value="2002">2002</option>
                                       <option value="2003">2003</option>
                                       <option value="2004">2004</option>
                                       <option value="2005">2005</option>
                                       <option value="2006">2006</option>
                                       <option value="2007">2007</option>
                             </select ></td></tr>
                             <tr>
                                  <td><input type="hidden" name = "dob" /> </td>
                                  <td nowrap="nowrap"><input type="submit" value="Submit" /></td>
                             </tr>
                             </table>
                        </form>
                   </td>
    <td width="40"></td>
    <td width="200" valign="top">
                   <div id="headlines">
    <jsp:include flush="true" page="../templates/profile.jsp"/>
    </div>
                   </td>
    </tr>
    </table>
              </td>
    <td> </td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td><jsp:include flush="true" page="../templates/footer.jsp"/></td>
    </tr>
    </table>
    </body>
    </html>

    i think normally u will get data from databsae as objects.they are like java beans having getter and setter methods.so you create a collection of those objects like collect all the objects coming from database into an arraylist or....
    suppose you want to populate the dropdown box with say "username" from database object s, your code will look like that
    <html:select property="name">
    <html:options collection="databaseList" property="username" />
    </html:select>
    "databaseList" is collection(say.. ArrayList) of objects you are getting from database.this dropdown will contain all the "usernames" you are getting from database.

  • How to retrieve value from xml file

    hi all,
    can somebody pls tell me how to retrieve value from xml file using SAXParser.
    I want to retrieve value of only one tag and have to perform some validation with that value.
    it's urgent .
    pls help me out
    thnx in adv.
    ritu

    hi shanu,
    the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
    pls have a look at the following code snippet.
    public class XMLValidator {
    static ArrayList strXXX = new ArrayList();
    public void validate(){
    factory.setValidating(true);
    parser = factory.newSAXParser();
    //all factory code is here only
    parser.parse(xmlURI, new XMLErrorHandler());     
    public void setXXX(String pstrXXX){          
    strUpn.add(pstrXXX);
    public ArrayList getXXX(){
    return strXXX;
    class XMLErrorHandler extends DefaultHandler {
    String tagName = "";
    String tagValue = "";
    String applicationRefNo = "";
    String XXXValue ="";
    String XXXNo = "";          
    XMLValidator objXmlValidator = new XMLValidator();
    public void startElement(String uri, String name, String qName, Attributes atts) {
    tagName = qName;
    public void characters(char ch[], int start, int length) {
    if ("Reference".equals(tagName)) {
    tagValue = new String(ch, start, length).trim();
    if (tagValue.length() > 0) {
    RefNo = new String(ch, start, length);
    if ("XXX".equals(tagName)) {
    XXXValue = new String(ch, start, length).trim();
    if (XXXValue.length() > 0) {
    XXXNo = new String(ch, start, length);
    public void endElement(String uri, String localName, String qName) throws SAXException {                    
    if(qName.equalsIgnoreCase("XXX")) {     
    objXmlValidator.setXXX(XXXNo);
    thnx & Regards,
    ritu

Maybe you are looking for

  • Pop battery cover off, screen fails on Treo Pro.

    Second time this has happened, I apply barely enough to remove the cover and the screen fails.  Any reason why the Treo Pro would do this?  A soft reset clears it but still weird nonetheless. When I mean fail, the entire display is blank but the keyb

  • Flash not working in FF3

    Hello I recently updated my flash player to version10 and ever since, I haven't been able to view a site seal on my own website properly in Firefox 3. The seal should have my website name scrolling across it (this works in IE7) and should be crisp, n

  • Clip Shelf Vs Timeline: Quality Difference

    hi there. my question is why a picture or a clip loses its original quality once it's dragged into the timeline from the clip shelf? it no longer looks as crystal and sharp in the timeline as its original copy on the clip shelf.

  • HT5622 What is a pass code

    Trying to update by installing a notified item in settings. Being asked for a pass code. What is this ?

  • Issue with normal correction.

    Hello, I am configuring ChaRM in SolMan system. I am able to perform the steps mentioned in the RKT. But currently I am facing 2 issues. 1. There is no action as "Create Change Request" in the support message. I can see only "Create Change Document".