JSP bean info needed

I have a String stored in my bean and want to get the String from the bean and place it into mySQL database from a JSP page. i want to use the string to use as a search parameter in the select statement. Can this be done and if so...HOW?

Also how do you clear the contents of a bean?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You didn't post any code...well, what i can guess is..if u have set and get methods in ur java class...then call the method in ur jsp...and used it in the query...


String searchstring = instance.getSome();

then in query...

select * from ur_table where something like "'+ searchstring+'%";

then u can use set method to reset the value...


if u have any problems, then try to post ur code..may be we can help u better then.

happy working
sredmusarmAuthor Commented:
I don't understand what you mean above...please try and explain more
Ryan ChongCommented:
Try example below:

Example of bean:

package app;

import java.util.*;

public class Submission extends Object

private String email = "";

public void setEmail(String value)
          this.email = value;
     public String getEmail()
          return email;

To get the value, use:

In your JSP:

<%@page import="app.*"%>
<jsp:useBean id="sub"       scope="session"                  class="app.Submission"/>

<jsp:setProperty name="sub" property="email"                  param="email"/>


Where the form is posted value of field "email".

Hope this helps
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Ryan ChongCommented:
For more information, you can refer to http://www.jspin.com/ and http://www.jspinsider.com/ for java bean and database connection.

sredmusarmAuthor Commented:
well i have changed it up but i'm not getting the results needed. When i do the query in the database i get the results but i'm not getting anything coming up on the screen...anyone know why? The error is near the While loop

 String fname, lname;
            boolean doneheading = false;
            dbconn = DriverManager.getConnection("jdbc:mysql://localhost/nutrition","saundersk","kevin");
            sql = dbconn.prepareStatement("SELECT first_name, last_name FROM member_info WHERE username = ?");
            sql.setString(1, request.getParameter(mybean.getUsername()));
            results = sql.executeQuery();
                 if(! doneheading)
                      doneheading = true;
                fname = results.getString("first_name");
                lname = results.getString("last_name");
Ryan ChongCommented:
>>sql.setString(1, request.getParameter(mybean.getUsername()));

This line looks weird, try:

sql.setString(1, request.getParameter("Username");

sql.setString(1, mybean.getUsername());

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This line is combining two different things, one is the request parameters and the second is the bean value.

sql.setString(1, request.getParameter(mybean.getUsername()));

To set the parameter using the bean use


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.