• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to retrive values from the database

 
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Craig
I failed to retrive the value of price from database.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}

}
 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic