retrieving data from database to jsp

Hi all

I am new member to SDN.

This is my first post.

My request is:

I have written a servlet to send data to the database(Access).

Now i want to retrive the data from database using servlet and display in my jsp page.

I have done the process but iam getting the null value in my jsp page.

Can anyone suggest me what do change.

Thanku.

[390 byte] By [want2knowabt_javaa] at [2007-11-27 8:15:53]
# 1

Hi,

If you post some of your code it'll be helpful for us to understand where is exactly the problem.

you can try by writing a java class to read data from the database and set the values in to a java bean [we call it a DTO] and this dto object is set as request attribute and then the sevelet will send the control to the jsp. in jsp we'll get this attribute and display the results.

Regards,

Rakesh

rakesh_mscita at 2007-7-12 20:00:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Hi Sir

Thanku for ur response.

thats fine

as i told i cud send data 2 database.

for retreiving data my servlet code is somewat like

...........

...........

{

rs= st.executeQuery("select * from CarsHome where CarType='Comfort' ");

while(rs.next())

{

s1=rs.getString(3);

s2=rs.getString(4);

s3=rs.getString(5);

// out.println(s1);

ses.setAttribute("Price",s1);

ses.setAttribute("priceper",s2);

ses.setAttribute("extra",s3);

}

And in jsp i wrote

<td><%=price%></td>

<td><%=priceper %></td>

<td><%=extra %></td>

here for price,priceper,extra iam getting null values displayed.

check this out pls

thanku.

want2knowabt_javaa at 2007-7-12 20:00:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Hi

use this...

<td><%=(price!=null?price:"") %></td>

<td><%=(priceper!=null?priceper:"") %></td>

<td><%=(extra!=null?extra:"") %></td>

;)

jpadrona at 2007-7-12 20:00:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Hello Sir

Thanku very much

ur code works.

But the problem is iam having 7 rows in my table and 3 columns sud be retreived frm each row.

And according 2 ur code i need 2 take individual string for each column field.

that means i need to take 21 strings .

I think it becomes 2 big process.Can i have any other option.

Pls do let me know.

Thanku

Radhi.

want2knowabt_javaa at 2007-7-12 20:00:44 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...