Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


megha singhal
bean object
1 Answer(s)      2 years and 4 months ago
Posted in : JSP-Servlet


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.


Advertisement
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...="top"> |Accessing Bean Properties | <table cellpadding="2
Advertisements
Bean
Bean  what is bean? how to use bean   HTML Code: Contents MOBILE STORE HOME PRODUCTS IMAGES COMPANY BRANCHES DEALERS FEEDBACK       Username       Password
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
Managed Bean
Managed Bean  What is Managed Bean
Java Bean
Java Bean  How to run java bean program in Netbeans
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
Java Bean
Java Bean  What is Java Bean?   I got my answer already here: http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks a lot
entity bean
/ejb/entity-bean-example.shtml
Mean by Bean Scope
Mean by Bean Scope  What is Bean Scope
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 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
object of object class
object of object class  what do u mean by "object of object class
bean area - SQL
bean area  how to print bean area in excel sheet from oracle forms
A Message-Driven Bean Example
A Message-Driven Bean Example   ... messages asynchronously,  a Message-driven bean is used. Message driven... the following characteristics: A message-driven bean?s instances retain
JSF Manage Bean
JSF Manage Bean   how to register JSF manage bean? Please give me an example. Thanks!   JSF Manage Bean Example
Special Bean Types of WebApplicationContext
In this section, you will learn about Special Bean Types in the WebApplicationContext
An Entity Bean Example
with the @Stateless annotation, which tells the container that the bean object... creates one object and injects it into the session bean.  ... for the management of the persistent data and object/relational mapping. Java Persistence API
bean - JSP-Interview Questions
bean  what is use bean in jsp?  Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/using-bean-counter.shtml http://www.roseindia.net/jsp/java-bean-example-jsp.shtml Hope
JAVA BEAN WITH ORACLE FORMS
JAVA BEAN WITH ORACLE FORMS  Hi..I am doing my final year Project.. I need the ste-by-step procedure to integrate a bean with oracle forms? Please help me
Java Bean Properties
Java Bean Properties  What are the properties of a normal java Bean(Not EJB)   HI Friend, Please visit here: http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks
Session Bean Example
Session Bean Example  I want to know that how to run ejb module by jboss 4.2.1 GA (session bean example by jboss configuration )?   Please visit the following link: http://www.roseindia.net/javabeans
message driven bean example
message driven bean example  can any one tell me how to develop and execute ---------- j2ee message driven bean example in weblogic server with (netbeans or eclipse).   Have a look at the following link: http
Stateless Bean Error
Stateless Bean Error  Ejb stateless bean giving following error,please help me. 11:49:54,894 INFO [STDOUT] Error:$Proxy72 cannot be cast... are providing you a link that will illustrate you more clearly about Stateless Bean
java bean - EJB
java bean  difference between java bean and enterprice java bean  first of all dont compare java bean with enterprise java bean because enterprise java bean is a techonology where we can develope business logic
Error in simple session bean ..................
Error in simple session bean ..................  Hi friends, i am trying a simple HelloWOrld EJb on Websphere Applicatiopn server 6.1. Can any..."); Context initialContext = new InitialContext(props); Object objref
Java Bean - Java Beginners
Java Bean  Sir, How can i add a java bean into a target GUI.... Thanking you Pabitra Kr Debanth.   Hi friend, Java Bean classes must..., it will be a visible Java Bean. Java Beans may also be invisible
java bean code - EJB
java bean code  simple code for java beans  Hi Friend... the Presentation logic. Internally, a bean is just an instance of a class. Java Bean Code: public class EmployeeBean{ public int id; public
Stateless Bean - EJB
Stateless Bean  Hi everybody, I m encountring a problem in stateless bean. I have taken a Integer type input in Client file, at the time of running the program it gives error java.lang.NumberFormatException : null. Please
Input in Stateless Bean - EJB
Input in Stateless Bean  Hello, I am having problem in taking the input in stateless bean, when I am trying to get integer or double type input from the user in the client file, It shows me the error
Ejb message driven bean
bean       This tutorial explains you the process which are involved in making a message driven bean using EJB. Mesaage driven bean in EJB have the following features:- 1) is a JMS listener
Spring Bean Post Processor
postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } public Object postProcessAfterInitialization(Object bean, String beanName...Spring Bean Post Processor The interface BeanPostProcessor allows custom
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
object creation
object creation  when will java object is created? is it at runtime or compiletime
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
How to add a bean in spring application?
How to add a bean in spring application?  Hi, How to add a bean in spring application? Thanks
What are Bean scopes in Spring Framework
What are Bean scopes in Spring Framework  Hi, What are Bean scopes in Spring Framework Thanks
What is Bean lifecycle in Spring framework?
What is Bean lifecycle in Spring framework?  HI, What is Bean lifecycle in Spring framework? Thanks
bean life cycle methods in spring?
bean life cycle methods in spring?  bean life cycle methods in spring
bean creation exception
bean creation exception  hi i am getting exception while running simple spring ioc program Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class
Chapter 13. Enterprise Bean Environment
enterprise bean has for the referenced administered object. The resource... Chapter 13. Enterprise Bean EnvironmentPrev .... Enterprise Bean Environment Identify correct and incorrect
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
Use Java Bean In Servlets
Use Java Bean In Servlets In this you will learn how to use Java Bean in Servlets. For this purpose, we have created a Bean named 'Person' and defined three variables with their setters and getters. Then we have created an object
calling a session bean bean from servlet using netbeans - EJB
calling a session bean from servlet using netbeans  How to call a session bean from servlet using netbeans in Java
Spring Bean Example, Spring Bean Creation
Basic Bean Creation The Spring bean can typically be POJO(Plain Old Java Object) in the IoC container. Here in this tutorial you will see at first a simple java bean file having two methods getMessage() and setMessage() and a default
Cmp Bean - EJB
Cmp Bean   I want to create connection pool in admin console in sun app server the data base is sql server, I gave the resource type is javax.sql.DataSource, and the datasource class name is came automatically called
Advertisements
 

 

 

DMCA.com