bean object

bean object

i have to retrieve data from the database and want to store in a variable using rs.getString and that variable i have to use in dropdown in jsp page.

View Answers

April 4, 2012 at 11:47 AM

1)Bean.java:

package form;
import java.sql.*;
import java.util.*;
public class Bean {

public List dataList(){
ArrayList list=new ArrayList();
try{
     Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from data");
           while(rs.next()){
               list.add(rs.getString("name"));

}
}
catch(Exception e){}
return list;
}
}

2)BeanInServlet.java:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BeanInServlet extends HttpServlet{
    protected void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException{
        form.Bean p = new form.Bean();
        List list=p.dataList();

        req.setAttribute("data", list);
        RequestDispatcher rd = req.getRequestDispatcher("/jsp/beandata.jsp");
        rd.forward(req, res);
    }
}

3)beandata.jsp:

<%@page language="java" import="java.util.*" %>
<html>
<body> 
<select name="name">
<option value="Select">Select</option>
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
for (itr=data.iterator(); itr.hasNext(); ){
%>
<option value="<%=itr.next()%>"><%=itr.next()%></option>
<%}%>
</select>
</body>
</html>

For more information, visit the following links:

http://www.roseindia.net/jsp/java-beans.shtml

http://www.roseindia.net/jsp/servlet-jsp-data-list.shtml









Related Tutorials/Questions & Answers:
bean object
bean object  i have to retrieve data from the database and want to store in a variable using rs.getString and that variable i have to use in dropdown... java.util.*; public class Bean { public List dataList(){ ArrayList list=new
Access properties of bean from request object using OGNL.
Access properties of bean from request object using OGNL. In this section, we will introduce you how to access beans properties from request object using...;center" valign="top"> |Accessing Bean Properties | <table
Advertisements
Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.
an entity bean's primary key and object identity. Prev Chapter 8... and incorrect statements or examples about an entity bean's primary key and object identity. From the viewpoint of the Bean Provider, entity objects have
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
Bean
Bean  what is bean? how to use bean   HTML Code: Contents MOBILE STORE HOME PRODUCTS IMAGES COMPANY BRANCHES DEALERS FEEDBACK       Username       Password
object of object class
object of object class  what do u mean by "object of object class
Managed Bean
Managed Bean  What is Managed Bean
object creation
object creation  when will java object is created? is it at runtime or compiletime
Java Bean
Java Bean  How to run java bean program in Netbeans
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
Java Bean
Java Bean  What is a Java Bean?   A Java Bean is a software component that has been designed to be reusable in a variety of different environments
Object reference not set to an instance of an object
Object reference not set to an instance of an object  Object reference not set to an instance of an object
Session Object
Session Object  Why do we require Session Object?  Hello.... The session object is used by the developers to store and retrieve user's related data such as login details. The javax.servlet.http.HttpSession object
Java Bean
Java Bean  What is Java Bean?   I got my answer already here: http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks a lot
Mean by Bean Scope
Mean by Bean Scope  What is Bean Scope
ArrayList object
ArrayList object  i have am ArrayList object it containg data base records in it, now i want to display this ArrayList object data in my jsp programe, plz help me
object as argument
object as argument  what happens when we pass a object into a method???if java is pass by value how does this makes a difference.....pllzzz give me more clarification on why we pass objects in a margument
Java object
Java object  Which class should you use to obtain design information about an object
Object Creations
Object Creations  String a[][]=new String[10][20]; The above line how many objects are created
Object
Object       An object...). In an object, variables store values for later use and methods are the unit... are the basic units of the object-oriented programming. Objects are the part of our day
Java object
Java object  What is mutable object and immutable object?  An Immutable object is a kind of object whose state cannot be modified after it is created. This is as opposed to a mutable object, which can be modified
Version of bean-displaytag>bean-displaytag dependency
List of Version of bean-displaytag>bean-displaytag dependency
Session Object
Session Object   What is the Max amount of information that can be saved in a Session Object ?   There is no such limit on the amount of information that can be saved in a Session Object. The only limit is the Session
object array
object array  Hi i have array that is object[] obj= { new string("hi"), new vector().add(10), new hashmap().setkey()} display(obj); display(object{[] obj) {} Now my question is what is the string length and how to retrieve
entity bean
/ejb/entity-bean-example.shtml
Vector object[]
Vector object[]  I want to create payslip in java public Vector...(); Object[] value = new Object[] {"Employee Name",f.ename.getSelectedItem()}; rec.add(value); value = new Object[] {"Mary-Kate Olsen", "Ashley
class and Object
(Object of B is referenced by A) Variable: a ThanksADS_TO_REPLACE_2
implect object
implect object  how i implment implect object   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 http://www.roseindia.net/help/java/o/jsp-implicit-objects.shtml http://www.roseindia.net/jsp
constructor or object
constructor or object  object or construct which create first?   A constructor is always created first. Here is an example: class Example { Example(String st){ System.out.println(st); } public
object and method
object and method  a college would like to automate managing courses offered to students. initially only three courses are involved. each courses has... and an application that creates the necessary object
What is bean wiring?
What is bean wiring?  Hi, What is bean wiring? Thanks
What is Bean Factory ?
What is Bean Factory ?  Hi, What is Bean Factory ? Thanks
Bean
Bean
Object slicing
Object slicing  I have a program as bellow: #include<iostream.h> #include<conio.h> class A { public: int x; A() { x=10; } }; class B:public A { protected: int y
Class and object
(); You are creating the object of subclass Thanks
Java Object
Java Object         Object is the basic entity of object oriented programming language. Object... properties of the class or its group. Java object is an instance of the class. It takes
Session Bean
is a Session bean   A session bean is the enterprise bean that directly.... A session bean represents a single client accessing the enterprise application.... A session bean makes an interactive session only for a single client and shields
What is an object's lock and which object's have locks?
What is an object's lock and which object's have locks?   Hi, What is an object's lock and which object's have locks? Thanks
View object in JSF
View object in JSF  What is view object
A Message-Driven Bean Example
A Message-Driven Bean Example   ... messages asynchronously,  a Message-driven bean is used. Message driven... the following characteristics:ADS_TO_REPLACE_1 A message-driven bean?s
bean area - SQL
bean area  how to print bean area in excel sheet from oracle forms
JSF Manage Bean
JSF Manage Bean   how to register JSF manage bean? Please give me an example. Thanks!   JSF Manage Bean Example
Java object clone
Java object clone  What is criteria for a object to get cloned
How to disable an HTML object?
How to disable an HTML object?  How to disable an HTML object
assign object properties
assign object properties  How do you assign object properties
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
Potential leak of an object XCode
Potential leak of an object XCode  What is potential leak of an object XCode
implementation object in C
implementation object in C  how to create and implement an object in C
use of object tag
use of object tag  how to use object tag in html

Ads