How to get list from mysql

How do I get a list from my database. I am using mysql and it says that method is not supported.The method I use is getResultList.Please reply
[163 byte] By [aniketh_parmara] at [2007-11-27 1:34:15]
# 1
Just convert the ResultSet to List<Dto> yourself.
BalusCa at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
public List getToys() {try {return CM.executeQuery("SELECT toyid FROM Toy") .getResultList();} catch (Exception ex) { System.out.print("Exception: "+ex.getMessage());}}Wht changes do I make in this. Can u please suggest
aniketh_parmara at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Just loop through the ResultSet and map each row to a Toy and add it to a List<Toy>.
BalusCa at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I am confused to how to get data on JSP. Please dont mind me. This is my first bean application.

This is one of the function in ToyDBAO.java class

public List<Toy> getToys()

{

try {

ResultSet rs = CM.executeQuery("SELECT * FROM Toy"); // CM is a connection object instantiated when i declare an object of ToyBDAO

while (rs.next())

{

Toy t = new Toy();

t.setToyid(rs.getString(1));

System.out.print(t.getToyid());

t.setName(rs.getString(2));

t.setPrice(rs.getInt(3));

t.setDescription(rs.getString(4));

t.setImageid(rs.getString(5));

toys.add(t); //toys is a arraylist.

}

}

catch (Exception ex)

{

System.out.print("Exception: "+ex.getMessage());

}return toys;

}

--

I call this function from one of the class called ToyDB.java

this is the function

public List getToys() {

ToyDBAO DB = new ToyDBAO();

return DB.getToys();

}

Now some one please tell me wht code should I write in jsp do display result.

aniketh_parmara at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Any one please reply to my above post. I am stucked up....Please helpp.. Frds
aniketh_parmara at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

1.in jsp page use <use bean id> tag to ur class.

2.create a array list in ur jsp page.

3.Arraylist object = get the values from database();//call that function which is having list objects.

5.iterate thro the arraylist using get()

4.Use <%=%> to output the result in jsp

kamal_shana at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Hi,

I am not able to clearly get ur requirements. Assuming that you have records in mysql database and needs to populate the specific column values in a list box. I am prescribing a sample jsp page.

<html>

<head>

<title> Web Application </title>

</head>

<body>

<form name="frm" method="post" action="loadlist.jsp">

<select name="lst" id="lst">

<%@ page language="java" import="java.sql.*"%>

<%

Class.forName("org.gjt.mm.mysql.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbmaintain","root","");

Statement stm = con.createStatement();

ResultSet rs = stm.executeQuery("select fname from userdetail");

while (rs.next())

{

%>

<option value=<%=rs.getString(1)%>> <%=rs.getString(1)%> </option>

<%

}

%>

</select>

</form>

</body>

</html>

In above code snippet i had implemented to list the name to the listbox in the page.

Get back to me if the code doesnot work or else if you have some other requirements.

Thanks&Regards,

Michael

RealStuffa at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
hello aniketh_parmar,first i want to know . r u going to display the DB values to the dropdown box.? or just to display it in a page?
kamal_shana at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
I want to display data through java beans. I have shown above which methods I am using to get info from database. My prob is I am not able to show data on jsp.Please show me how to do thatThanks for reply
aniketh_parmara at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Hello frds I am now able to display data on JSP files using Beans.Special thanks to every one
aniketh_parmara at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
hii , i wanted to know how display the selected values from the list box (with multiple select der ). can you pls help me out .
nssachina at 2007-7-12 0:41:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...