Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 677
  • Last Modified:

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?
0
sredmusarm
Asked:
sredmusarm
1 Solution
 
fargoCommented:
Hii,
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...

say...

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...

instance.setSome("");

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

happy working
fargo
0
 
sredmusarmAuthor Commented:
I don't understand what you mean above...please try and explain more
0
 
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"/>


<%=sub.getEmail()%>

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

Hope this helps
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

cheers
0
 
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();
     
            while(results.next())
            {
                 out.println("1");
                 if(! doneheading)
                 {
                     
                      doneheading = true;
                     
                 }
                fname = results.getString("first_name");
                lname = results.getString("last_name");
                 out.println(fname);
                 out.println(lname);
                 
            }
0
 
Ryan ChongCommented:
>>sql.setString(1, request.getParameter(mybean.getUsername()));

This line looks weird, try:

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

or
     
sql.setString(1, mybean.getUsername());
0
 
Binary1Commented:
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

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




0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now