Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

bean object

Ads

 
 

Share on Google+Share on Google+

megha singhal
bean object
1 Answer(s)      5 years and 3 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.

Ads
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


Ads









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
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
Bean
Bean  what is bean? how to use bean   HTML Code: Contents MOBILE STORE HOME PRODUCTS IMAGES COMPANY BRANCHES DEALERS FEEDBACK       Username       Password
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
object of object class
object of object class  what do u mean by "object of object class
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
Version of bean-displaytag>bean-displaytag dependency
List of Version of bean-displaytag>bean-displaytag dependency
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
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
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
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
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
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
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
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
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
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