Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 3rd, 2003, 06:47 AM
rubertoga rubertoga is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 2 rubertoga User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Get data from form to query Access database using JSP

I have a form that has textboxes called title2 and surname2 I'm using them to get data from the user to enter it into an SQL search for my shopping cart. I do not think the way I have called the JSP into the SQL to get the data from the form is correct (see after LIKE in SQL code) as it brings up the following error:
Message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException

If I put an error page in the only error I get is it states "Null".

If I input the values for the search manually i.e. LIKE '%queen%' or get all records in the Ebook table from the database without any conditions the records are displayed properly in the shopping cart, so it must be the JSP elements that are not right.

Let me know if you need anymore information/code like the Product and shoppingbasket classes. Any help would be gratelfully appreciated.

The SQL code for the shopping cart page is as follows:

<%@ page language="java" contentType="text/html"
import="ShoppingBasket,Product"
%>

<html>
<head> <title>Welcome to the Shop</title></head>
<body>

<table width="385" border="0" cellspacing="0" cellpadding="2">
<tr>
<td colspan="4"><b><u>Search Results</u></b></td>
</tr>
<tr>
<td colspan="4" align="right">
<a href="<%= response.encodeURL("shop-basket.jsp") %>">
<img src="images\viewbasket.gif" border="0" alt="View Basket"></a>
</td>
</tr>
<tr>
<td><b>Book ID</b></td>
<td><b>Title</b></td>
<td><b>Price</b></td>
<td></td>
</tr>

<%
String title2 = request.getParameter("title");
String surname2 = request.getParameter("surname");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbcdbc:Novbase","","");
java.sql.Statement statement = connection.createStatement();
java.sql.ResultSet RS = statement.executeQuery("SELECT * FROM Author RIGHT JOIN Ebook ON Author.author_id = Ebook.author_id WHERE Ebook.title LIKE '%" + title2 + "%' AND surname LIKE '%" + surname2 + "%'");

int rowCounter = 0;
while(RS.next())
{
String item_id = RS.getString("item_id");
String title = RS.getString("title");
String description = RS.getString("description");
String price = RS.getString("price");
String surname = RS.getString("surname");

rowCounter++;
String bg = (rowCounter %2 !=0) ? "#C0C0C0" : "#FFFFFF";
%>
<tr bgcolor="<%= bg %>">
<td><%= item_id %><br>
<%= surname %></td>
<td><b><%= title %></b><br/><%= description %></td>
<td>£ <%= price %></td>
<td><a href="<%= response.encodeURL("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price) %> ">
<img src="images\addtobasket.gif" border="0" alt="Add To Basket"></A></td>
</tr>
<%
}

RS.close();
connection.close();
%>

</table>

<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>

<% String title = request.getParameter("title");
if(title!=null)
{
String item_id = request.getParameter("item_id");
double price = Double.parseDouble(request.getParameter("price"));
Product item = new Product(item_id, title, price);
basket.addProduct( item );
}
%>

</body>
</html>

Reply With Quote
  #2  
Old April 6th, 2003, 03:10 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
In this line
Code:
java.sql.ResultSet RS = statement.executeQuery("SELECT * FROM Author RIGHT JOIN Ebook ON Author.author_id = Ebook.author_id WHERE Ebook.title LIKE '%" + title2 + "%' AND surname LIKE '%" + surname2 + "%'");

the title2 variable is probably null. The getParameter(String) method of the request wil return null if no variable was found in the request by that name. You should always check to see if your variables are null after retrieving them from the request.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Get data from form to query Access database using JSP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway