File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to retrive values from the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to retrive values from the database" Watch "How to retrive values from the database" New topic
Author

How to retrive values from the database

rushikesh kale
Ranch Hand

Joined: Jan 25, 2005
Posts: 41

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 ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
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

Joined: Jan 25, 2005
Posts: 41

Hi Craig
I failed to retrive the value of price from database.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
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

Joined: Jan 25, 2005
Posts: 41

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

Joined: Jan 25, 2005
Posts: 41

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

Joined: Mar 19, 2002
Posts: 405
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

Joined: Jan 25, 2005
Posts: 41

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrive values from the database
 
Similar Threads
TOPLINK
Newbie check box validation on jsp - HELP!!
form value is missing some times
Cannot retrieve init parameter through JSP file
How to Retrive the hidden field value