Forums Register Login

How to retrive values from the database

+Pie Number of slices to send: Send
Hi Guys!
I Have a little problem in retriving the value of Data item from my database . I am also using Beans for my JSP page. In my Bean file i write follg. code to retrive value of Price :

In jsp i use:- Price :<jsp:getProperty name ="product" property="price"/><BR>
But i failed ! please help me!
thanks

[edited to add code tags]
[ January 29, 2005: Message edited by: Jeanne Boyarsky ]
+Pie Number of slices to send: Send
Can you elaborate more on what

But i failed



means?

Are you generating an error on the jsp page and/or are you not getting the desired results?

A little more information would be helpful.

Thanks.
+Pie Number of slices to send: Send
Hi Craig
I failed to retrive the value of price from database.
+Pie Number of slices to send: Send
Well, the first thing I would do is verify that data exists based on your query for specific "ID" and you are able to return the desired results.

I would do this by using a plain old regular test Java program(NO JSP) with your java bean. This should be done before we insert this same java bean code into your JSP page.

+Pie Number of slices to send: Send
Well i tried hard but still i get the error as Null pointer exception , thats why now i try to send you my program.
1.name coonectionBean.java)
Code:
package supply;
import java.io.*;
import java.sql.*;

public abstract class connectionBean
{
private String driver="sun.jdbc.odbc.JdbcOdbcDriver";
private String url="jdbc dbc:rushi";
protected Connection conn;
public connectionBean() {}
public void connect() throws Exception
{
Class.forName(driver);
conn=DriverManager.getConnection(url);
System.out.println("I connect");
}
public abstract void cleanup() throws Exception;
public void takedown() throws Exception
{
cleanup();
conn.close();
}

}
+Pie Number of slices to send: Send
Sorry I by mistake fwd a previous incomplete reply:


Well i tried hard but still i get the error as Null pointer exception , thats why now i try to send you my program.
1.name coonectionBean.java)
Code:
package supply;
import java.io.*;
import java.sql.*;

public abstract class connectionBean
{
private String driver="sun.jdbc.odbc.JdbcOdbcDriver";
private String url="jdbc dbc:rushi";
protected Connection conn;
public connectionBean() {}
public void connect() throws Exception
{
Class.forName(driver);
conn=DriverManager.getConnection(url);
System.out.println("I connect");
}
public abstract void cleanup() throws Exception;
public void takedown() throws Exception
{
cleanup();
conn.close();
}
}

2.name: Order.java
Code:

%>
<jsp:setProperty name ="product" property ="id" value='<%=id%>'/>
<jsp:setProperty name="product" property="qty" value='<%=qty%>'/>
<jsp:setProperty name ="product" property ="disc" value='<%=disc%>' />
ID :<jsp:getProperty name ="product" property="id"/><BR>
Quantity:<jsp:getProperty name ="product" property="qty"/><BR>
Discount :<jsp:getProperty name ="product" property="disc"/><BR>
Price :<jsp:getProperty name ="product" property="price" param='<%=id%>' /><BR>
Name :<jsp:getProperty name ="product" property="name" /><BR>
Total :<jsp:getProperty name ="product" property="total"/><BR>

4>I take value of id,qty,disc using OrderMain.html page.
5>I am using Java Web server

[edited to add code tags]
[ January 30, 2005: Message edited by: Jeanne Boyarsky ]
+Pie Number of slices to send: Send
Can you provide a copy of the exact error stack? I am trying to see if this is a JDBC error or a JSP error.


Thanks.
+Pie Number of slices to send: Send
hi
Now i changed my code littile bit,In fuction getPrice in Order.java bean instead of taking parameter i use getid fuction as follows:
public int getPrice()
{try
{
s=conn.createStatement();
priceis =s.executeQuery("Select * from supply where ID ="+this.getId());
while(priceis.next())
{
String sprice=priceis.getString(3);
price=Integer.parseInt(sprice);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return price;
}
Now I atleast dosent get the error on web page.but i am still not getting the price from the table .i am getting default value of price i.e. price=100.

This is the error which i got on my java web server:
javawebserver: at com.sun.server.http.pagecompile.jsp.runtime.JspServlet.runSer
vlet(JspServlet.java:469)
javawebserver: at com.sun.server.http.pagecompile.jsp.runtime.JspServlet.proces
sJspPage(JspServlet.java:259)
javawebserver: at com.sun.server.http.pagecompile.jsp.runtime.JspServlet.servic
e(JspServlet.java:97)
javawebserver: at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
javawebserver: at com.sun.server.ServletState.callService(ServletState.java:226
)
javawebserver: at com.sun.server.ServletManager.callServletService(ServletManager.java:936)
javawebserver: at com.sun.server.ProcessingState.invokeTargetServlet(ProcessingState.java:423)
javawebserver: at com.sun.server.http.HttpProcessingState.execute(HttpProcessingState.java:79)
javawebserver: at com.sun.server.http.stages.Runner.process(Runner.java:79)
javawebserver: at com.sun.server.ProcessingSupport.process(ProcessingSupport.java:294)
javawebserver: at com.sun.server.Service.process(Service.java:204)
javawebserver: at com.sun.server.http.HttpServiceHandler.handleRequest(HttpServiceHandler.java:374)
javawebserver: at com.sun.server.http.HttpServiceHandler.handleRequest(HttpServiceHandler.java:166)
javawebserver: at com.sun.server.HandlerThread.run(HandlerThread.java:162)

Thanks
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1398 times.
Similar Threads
Cannot retrieve init parameter through JSP file
form value is missing some times
Newbie check box validation on jsp - HELP!!
How to Retrive the hidden field value
TOPLINK
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:02:51.