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.
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 objectbean 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
Advertisements
objectobject 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
BeanBean what is
bean? how to use
bean
HTML Code:
Contents
MOBILE STORE
HOME
PRODUCTS
IMAGES
COMPANY
BRANCHES
DEALERS
FEEDBACK
Username
Password
object creationobject creation when will java
object is created? is it at runtime or compiletime
Java BeanJava Bean How to run java
bean program in Netbeans
Object OrientedObject Oriented C++ is Purely
object oriented or not .Then why java called purely
object oriented
Java BeanJava 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
Session ObjectSession 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 BeanJava Bean What is Java
Bean?
I got my answer already here: http://www.roseindia.net/jsp/usingbeansinjsp.shtml
Thanks a lot
ArrayList objectArrayList 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 argumentobject 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 objectJava object Which class should you use to obtain design information about an
object Object CreationsObject 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 objectJava 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 ObjectSession 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 arrayobject 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
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 objectimplect 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 objectconstructor 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 methodobject 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 Object slicingObject 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
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
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 - SQLbean 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