Problem searching for data in database

hello, im facing a problem here. Actually i have 2 files,jsp and a javabean file. The jsp files basically contains a few radio buttons and a text field. Now what im planning to do here is if user enter a value in the text field and selects the appropriate radio button, it will basically perform a search. The problem here is its not displaying any results although that particular data is in the database.
Actually the real problem is its not passing the data to the javabean. This is how the statement looks like in the JSP file
String field = request.getParameter("searchfield");
ResultSet rs = ad.searchFirstName(field);
searchfield = name of the text field
ad = name of the usebean id
searchFirstName = name of the method in the javabean that will perform this search function
Now the javabean file
public ResultSet searchFirstName(String field)
This is how the method declaration looks like
the sql statement is stated as below
SELECT * from PersonalInfo where FirstName LIKE '%field%' order by FirstName;
Everything ok(no errors in code) but i realise that its not displaying any data. i think its not passing the value from the jsp text field to the javabean. This is because if i replace the "field" with a data in the database, it displays the data. But if i dont, it just dont display any data. How can i pass a variable that user enter in the jsp text field file to a javabean file for processing..
Pleaseee help..i have been working on this for quite some time. Thanks in advance..

You might need something like this:
String sql = "SELECT * from PersonalInfo where FirstName LIKE '%" + field + "%' order by FirstName";
Even better would be to use a prepared Statement and preventing bad field value like M'Hael from ruining your code (the quote in the name would break your SQL statement)
String sql = "SELECT * from PersonalInfo where FirstName LIKE ? order by FirstName";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, "%" + field + "%");
ResultSet rs = stmt.execute();Cheers,
evnafets

Similar Messages

  • Search for data in server based database.

    I have a web page (http://gosolivitahomes.com) where I can enter a search for data in my server based database.  If I enter a value less than $100,000 in Min Price I get no response.  For values >= $100,000 I get the correct response. Why?  Please help.

    Yesterday I got no properties under $100,000.
    To day I tried again and the first time I got 2 results, but when I went back and repeated the same thing, I got no result.
    Then, like John Waller suggested, I cleared my cache and the 2 result were back.
    Perhaps your problem is a template or other cms cache issue. I don't know very much about it, but when I had a login problem I had to disable user cache i the cms (Joomla).
    I hope you will solve the problem

  • Swing Applet in JSP: problem with fetching data from database

    i am facing a problem while fetching data from database using Swing Applet plugged in a JSP page.
    // necessary import statements
    public class NewJApplet extends javax.swing.JApplet {
    private JLabel jlblNewTitle;
    private Vector vec;
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    NewJApplet inst = new NewJApplet();
    frame.getContentPane().add(inst);
    ((JComponent)frame.getContentPane()).setPreferredSize(inst.getSize());
    frame.pack();
    frame.setVisible(true);
    public NewJApplet() {
    super();
    initGUI();
    private void initGUI() {
    try {
    this.setSize(542, 701);
    this.getContentPane().setLayout(null);
    jlblTitle = new JLabel();
    this.getContentPane().add(jlblTitle);
    jlblTitle.setText("TITLE");
    jlblTitle.setBounds(197, 16, 117, 30);
    jlblTitle.setFont(new java.awt.Font("Dialog",1,20));
    jlblNewTitle = new JLabel();
    this.getContentPane().add(jlblNewTitle);
    Vector vecTemp = getDBDatum(); // data fetched fm DB r stored here.
    jlblNewTitle.setText(vecTemp.get(1).toString());
    jlblNewTitle.setBounds(350, 16, 117, 30);
    jlblNewTitle.setFont(new java.awt.Font("Dialog",1,20));
    } catch (Exception e) {
    e.printStackTrace();
    }//end of initGUI()
    private Vector getDBDatum() {
    // fetches datum from oracle database and stores it in a vector
    return lvecData;
    }//end of getDBDatum()
    }//end of class
    in index.jsp page i have included the following code for calling this applet:
    <jsp:plugin type="applet" code="NewJApplet.class" codebase="applets"
    width="600" height="300">
    <jsp:fallback>Could not load applet...</jsp:fallback>
    </jsp:plugin>
    if i view it in using AppletViewer it runs perfectly and display the data in JLabel. (ie, both jlblTitle and jlblNewTitle).(ie, DATA FETCHES FROM db AND DISPLAYS PROPERLY)
    BUT IF I CLICK ON INDEX.JSP, ONLY jlblTitle APPEARS. jlblnNewTitle WILL BE BLANK(this label name is supposed to fetch from database)
    EVERY THING IS DISPAYING PROPERLY EXCEPT DATA FROM DATABASE!!!
    i signed the applet as follows :
    grant {
    permission java.security.AllPermission;
    Can any body help me to figure out the problem?

    This is the Swing Applet java code
    import java.awt.Dimension;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Vector;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.JScrollPane;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTree;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.SwingConstants;
    public class HaiApplet extends javax.swing.JApplet {
         private JLabel     jlblTitle;
         private JLabel     jlblNewTitle;
         private Vector     vec;
         * main method to display this
         * JApplet inside a new JFrame.
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              NewJApplet inst = new NewJApplet();
              frame.getContentPane().add(inst);
              ((JComponent)frame.getContentPane()).setPreferredSize(inst.getSize());
              frame.pack();
              frame.setVisible(true);
         public HaiApplet() {
              super();
              initGUI();
         private void initGUI() {
              try {               
                   this.setSize(542, 701);
                   this.getContentPane().setLayout(null);
                        jlblTitle = new JLabel();
                        this.getContentPane().add(jlblTitle);
                        jlblTitle.setText("OMMS");
                        jlblTitle.setBounds(197, 16, 117, 30);
                        jlblTitle.setFont(new java.awt.Font("Dialog",1,20));
                        jlblTitle.setHorizontalAlignment(SwingConstants.CENTER);
                        jlblTitle.setForeground(new java.awt.Color(0,128,192));
                        jlblNewTitle = new JLabel();
                        this.getContentPane().add(jlblNewTitle);
                        Vector vecTemp = getDBDatum();
                        jlblNewTitle.setText(vecTemp.get(1).toString());
                        jlblNewTitle.setBounds(350, 16, 117, 30);
                        jlblNewTitle.setFont(new java.awt.Font("Dialog",1,20));     
              } catch (Exception e) {
                   e.printStackTrace();
         }//end of initGUI()
         private Vector getDBDatum() {
              Vector lvecData = new Vector(10,5);
              Connection lcon = null;
              Statement lstmt = null;
              ResultSet lrsResults = null;
              String lstrSQL = null;
              String lstrOut = null;
              try {
                   OmmsDBConnect db = new OmmsDBConnect();
                   lcon = db.connectDb();
                   lstmt = lcon.createStatement(lrsResults.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
                   lstrSQL = "select DT_ID from P_DATATABLES";
                   lrsResults = lstmt.executeQuery(lstrSQL);        
                   int i = 0;
                   lrsResults.last();
                   int length = lrsResults.getRow();
                   System.out.println(length);
                   lrsResults.beforeFirst();
                   int recCount = 0;
                   while (lrsResults.next()) {
                        recCount++;
                        lvecData.addElement(new String(lrsResults.getString("DT_ID")));
                   //     System.out.println("ID :  " + lrsResults.getString(1));
                        i++;
                   }System.out.println("here 3 out fm while");
              catch(SQLException e) {
                   System.out.print("SQLException: ");
                   System.out.println(e.getMessage());
              catch(Exception ex) {
                   lstrOut = "Exception Occured " + ex.getMessage();
              finally {
                   try {
                        lrsResults.close();
                        lstmt.close();
                        lcon.close();
                        System.out.println("[DONE]");
                   catch(Exception e) {
                        System.out.println(e);
             }//end of finally
              return lvecData;
         }//end of getDBDatum()
    }//end of classOfcourse the above code compiles and runs well. in Applet Viewer
    I plugged the above Swing Applet in a JSP page index.jsp
    <jsp:plugin type="applet" code="NewJApplet.class" codebase="applets"
                   width="600" height="300">
         <jsp:fallback>Could not load applet...</jsp:fallback>
    </jsp:plugin>Every thing is working fine in AppletViewer...But if i view this in any browser, then only the jlblTitle is displaying. jlblNewTitle is not displaying(this label name is actually fetching from thedatabase)
    can any body help me regarding this matter.? Thx in Advance.

  • Clues about query's - Search for date type at INBOX

    Hello Everyone,
    At IC Webclient, does anyone experiment to add a new search date type at INBOX, at "search for date" search parameter?
    I added a new date type at Date Management, ZDATA_PR.
    When I try to assemble the query parts, I use something like this:
    CL CL_CRM_QUERYAUI_RUN_BTIL
    METH READ_BUSINESS_TRANSACTIONS
    CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
        EXPORTING
          iv_token     = 'DAT'
          iv_date_type = 'ZDATA_PAR'
          iv_from      = ls_query_aui-from
          iv_to        = ls_query_aui-to
        IMPORTING
          ev_qupart    = ls_qupart_range-querypart.
      APPEND ls_qupart_and   TO lt_query.
      APPEND ls_qupart_range TO lt_query.
    However, I'm rewarded with an error message telling me that I have problems with the query.
    Does anyone can give me clues how to perform this action? I'm clueless and there's not almost no information about this...
    Thanks and Kind Regards
    Bruno Garcia

    Just to solve a mistake at example code:
    CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
    EXPORTING
    iv_token = 'DAT'
    iv_date_type = 'ZDATA_PR'
    iv_from = ls_query_aui-from
    iv_to = ls_query_aui-to
    IMPORTING
    ev_qupart = ls_qupart_range-querypart.
    APPEND ls_qupart_and TO lt_query.
    APPEND ls_qupart_range TO lt_query.
    does anyone has a suggestion or a clue to give?
    Thanks
    Bruno

  • Having problems searching for music

    I just recently encountered a problem searching for music on the Itunes store. I searched under song title, and it didn't bring up any results. Then I searched for the same music under artist, and the music came up. What's weird here is that the music was always there, but it's not showing up when I try to search under song title. Can someone tell me what's going on here?

    If the song is a part of "Compilation", you cannot find it using Artist or Genres. But you can find it searching through Albums or Compilations. Try that, maybe that's you problem.

  • Search for data within a database table

    Hi everyone :)
    I'm trying to make it so that the user can search for a record by id #. So, i made an input dialogue thing so the user can enter a record #. Basically, i want the data to appear in their textboxes based on the record # inputted by the user. My attempt is shown below, and when I run it, I get this:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    Here's my code:
    public JButton getSearch()
              if (search==null)
                   search = new JButton("Search Database");
                   search.addActionListener
                        new ActionListener()
                             public void actionPerformed(ActionEvent ae)
                                  try
                                       String str_rec =
                                            JOptionPane.showInputDialog(
                                                 getFrame(),"Enter Record No");
                                       int recNo = 0;
                                       try
                                            recNo =
                                                 Integer.parseInt(str_rec);
                                       catch (NumberFormatException nfe)
                                            return;
                                       String select = "SELECT studId,studFirstName,studLastName " +
                                       "FROM Students " +
                                       "WHERE studId = '" + recNo + "' ";
                                       Statement statement = getConnector().getConnection().createStatement();
                                       ResultSet result = statement.executeQuery(select);
                                       System.out.println(recNo);
                                       getView().getId().setText(str_rec);
                                       getView().getFirstName().setText(result.getString("studFirstName"));
                                       getView().getLastName().setText(result.getString("studLastName"));
                                  catch (Exception e)
                                       e.printStackTrace();
              return search;
         }I hope I explained everything properly. If you could please help me, I'd very much appreciate it.
    Thanks in advance! :)
    - spidey

    "WHERE studId = '" + recNo + "' ";Why are you putting quote marks around a number? What type of database column is studId? Probably a numeric type (not character), right? Quotes go around string/character stuff, not numeric stuff.

  • Database-Searching for dates

    If I enter in an exact date (such as 7/9/06) in my database's Find layout that matches an existing record then AppleWorks finds the record. But I want to find all records that contain ANY date in the date field. If I type in a character in the date field that is bound to be present, such as 0 (zero), AppleWorks doesn't find anything. I have to enter an exact date. Is there a way to search for all records in which the date field is not empty?

    From the Organize menu, choose "Show All Records".
    Again from the Organize menu, choose "Match". In the dialog select the "All" dropdown and choose "Logical". Click on the "ISBLANK" entry, then from the left column click on the date field you're trying to search. Your search field should look like: ISBLANK('date')
    (... the parentheses will contain the actual name of the field you chose)
    Click "OK" and the matched records will have been selected.
    Again from the Organize menu, choose "Hide Unselected"

  • Problem in getting data into database with standard direct input program

    HI All,
    I am having problem which is not updating the records in MM01 or MM02 with standard direct input program. i have data in internal table. from that table i am trying to upload into database by using background job MRP_MATERIAL_MASTER_DATA_LOAD.
    when i execute my program it is showing message job is started. then i go into sm37 and seethe job status by executing. there also i am seeing job completed succesfully.
    but if i go to mm03 and find the materials are updated or created there i couldn't find the material numbers which are from internal table.
    So if ny one help me it wil be great.
    Thanks in Advance
    Venkat N

    Hi Anil,
    Thanks for your answer, but i am facing problem is i have material no and denominator and Actual UOM and nominator field values in the flat file.....
    by using RMDATIND direct input program with MRP_MATERIAL_UPLOAD as job name for background job while uploading data into database.
    here i am not getting data in to database, but when i execute the job in sm37 it is showing that message job processing successfully completed...this is my status..
    if u can help me in this it will be gr8ful..
    Thanks,
    Venkat N

  • Problems searching for not existing index entries

    Hi,
    we are creating a Java Fat Client Application with JDK 1.5.0_07 and compliance level 1.4. The GUI bases on the SWT libraries.
    The application ships with JavaHelp 2.0_02 (jh.jar).
    The helpset is dynamically merged.
    JavaHelp has problems e.g. during search for index entries, which does not exist. The JavaHelp Window does not react anymore. The rest of the application still works fine.
    Has someone encountered similar problems, found the reason and propably a solution?
    Thanks, Joerg.

    Hi Mikkel
    1) number attributes are only exposed in the complete search sample (search.jsp), not the others (usearch.jsp, tsearch.jsp, gsearch.jsp)
    2) Your understanding of the binary encoding is correct, except wk_queryexp package does not handle binary encoding. This is because that package
    is meant for 9.0.1 API, which only supports string attributes.
    In 9.0.2 and beyond, the encoding of number, date attributes is done in the query API layer in Java, using
    the Equals, GreaterThan, LessThan, Between query operators. Please take a look at search.jsp
    and see how they are used. The compile() method of the query operators will encode the values for you.
    Keep in mind that you should code your application to use the query API, as the encoding algorithm
    may change in the future.
    David

  • Searching for Data in the Report for a non-selected column in display.

    Hello,
    I have an interactive report as given below:
    select user, dept_name, sal, description, title from hr;
    Now, in the report display options I remove the title and description from the display as you know title and description are 2000 characters each.
    If I show then it takes the whole page to display one record and with this option I can search any text in the Title or Description columns.
    Now, I have hidden these two columns and when I search I do not see any records.
    Can any one tell me how to achieve this behaviour.
    What I am looking is, I do not show the column 'TITLE' or 'DESCRIPTION' and user show be able to search for any important data inside these columns.
    Please let me know how can we do this.
    Please point me to an already published article or solution or any help on this type.
    Appreciate your help on this.
    thanks
    Edited by: user648778 on Sep 18, 2008 6:13 PM

    As far as I can see this will not work. You could use a trick and make a query like this:
    SELECT USER, dept_name, sal,
              apex_item.hidden (10, mgrdescription || title)
           || '<img src="#IMAGE_PREFIX#some_nice_icon.gif">' title_description
      FROM hrThis would not display the title and description but an image and it would give you a possibility to filter on those.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How to search for data on the web and return to jsp

    I need to collect data from a web site and return that data to my jsp file. The page should consist of a web page in which the user search for available flights then I conect to easyjet automatically fill in the form and return the result from easyjet.com to my jsp file..Do anyone know how can I do this?? I need to use java for this and not cgi..I found also some JavaScripts that can perform the same thing..Thanks...

    Hi,
    are you able to change dynamically the  operation.url = "assets/data/shopping.xml";?
    i need to do that based on the users input.
    Thanks in advance,

  • How to search for data in active directory

    if i have an administrator priviledge, how can i search for user's data if i know his username from active directory.

    What form do you have the user's name in ?
    ANTIPODES\alberteString searchFilter = "(&(objectClass=user)(samAccountName=alberte))";[email protected] searchFilter = "(&(objectClass=user)(userPrincipalName=[email protected]))";Albert EinsteinString searchFilter = (&(objectClass=user)(givenName=Albert)(sn=Einstein))";or using Ambiguous Name Resolution (anr)String searchFilter = "(&(objectClass=user)(anr=Albert Einstein))";or it's even clever enough to useString searchFilter = "(&(objectClass=user)(anr=Einstein Albert))";

  • [CS5.5][Os X 10.7] Problem searching for file when placing a picture

    Hi,
    With this post, I would like to ask a question.
    In Indesign CS5.5 on Mac Os X, when placing a picture using the place option, there is in the top right corner a search field. When browsing to a certain network folder and trying to search for files whitin that folder, which have filenames containing a part of the search string, no files are found.
    For example: a folder containing 200 files with names starting with "sports baseball 001" up to "sports baseball 200". When searching for "baseball" no results are found.
    What I could find on the internet, are several discussions relating to huge problems with Spotlight on 10.7 and 10.8 and network drives.
    Does anyone know of any fix or plugin for Adobe Indesign that allows fast file search in a folder when placing a picture in a document?
    Whe have this issue with all our mac's running these versions of Os X and Adobe Indesign.
    Any feedback would be helpfull.
    John

    Good to hear that Adobe engineering is taking a look. However you might want to file a formal bug/feature report here: Wishform, to get it on record as a customer/user problem, and to perhaps attract additional requests from others who have the same problem.
    I'm not sure if the commercial Mac application Default Folder X would fix the problem. You might want to test their trial.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • Search for objects in database by name

    Want to search packages, views, table, functions for an object name 'company_search' . What is the query from data dictionary?
    Thanks

    user568155 wrote:
    Want to search packages, views, table, functions for an object name 'company_search' . What is the query from data dictionary?
    ThanksThere are several data dictionary views you can reference, including
    * DBA/ALL/USER_OBJECTS
    * DBA/ALL/USER_VIEWS
    * DBA/ALL/USER_SOURCE (may contain text internally in the TEXT column)
    * DBA/ALL/USER_ARGUMENTS
    You will have to search the _SOURCE view line by line for packaged procedures and functions.  To search packages you will have to loop through the source lines one by one to search for the text you want
    A query would look something like
    select object_name
      from dba_objects
    where object_name like '%COMPANY_NAME%';Edited by: riedelme on Sep 20, 2012 9:02 AM

  • Search for Data in all schema

    I have user_x
    I know in one of its tables.Column there is a value 99
    I need to write a script to search all tables under the schema form the value of 99 ?

    PLease have a look at the script in :
    http://it.toolbox.com/blogs/david/search-for-a-given-string-in-all-fields-of-an-entire-schema-24074
    It might help you meet your requirement.

Maybe you are looking for

  • CS5.5/OS X 10.8: Open/Save As dialog box resizing

    Since I have been using CS5.5 Web Design Premium in Mountain Lion, I cannot get the programs to remember me resizing the Open and Save As dialog boxes. Each time I Open or Save As, the windows default to about 720 x 540, which is annoyingly small on

  • Calling a function and passing parameters via Variables

    I've got an XML file that is loading in data and is calling functions. I've figured out how to call the methods from classes with variables set from the XML file: var functionToCall:String = xml.functions.func[0].to_fire.toString(); myClass[functionT

  • How to view sap standard 0P_PRFP1 query variable

    Hi Guys, I want to view the code for sap stadard query varibale Previous Period of Current Fiscal Year (SAP Exit) 0P_PRFP1. I have checked in TCode SE37. I know i can view customer exits by viewing Tcode CMOD. Is there a transaction to view SAP stand

  • Back ground programs running

    How do I actually close the apps after I am done using them. i have everything open in the back ground running and using up my battery.

  • Photoshop Images Appear Darker Online and in Microsoft Paint ---- Help Please!

    Hello, I have been losing my mind over this problem: Whenever I save images in Photoshop CS6, they appear darker and with more contrast online. I am using Windows 7 OS and have calibrated the monitor to the best of my abilities NOTE: My Proof Setup i