• 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

Error using getParameterValues method

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an issue that is probably more in line with a general Java question, but I'm writing a small servlet app and thought I would start here. I have a screen where people can select items to delete and if they don't select anything, I get a java.lang.NullPointerException error. Is there any way to test if my array variable deleteNames is null or not? In looking at the API, I know that if one element is returned, then the array length is equal to 1, but I don't know how to test the length if the original parameter was null.

I'm sure this is a simple thing to do, but I can't seem to find the right way to test if the array is populated or not.

My code snippet is below.

Thanks in advance.

Scott

-------------------------

String[] deleteNames = request.getParameterValues("deleteitems");
try {
Connection conn1 = (Connection) getServletContext().getAttribute("dbconn");
PreparedStatement stmt = conn1.prepareStatement("delete from baissue where issue_name = (?)");
PreparedStatement stmt1 = conn1.prepareStatement("delete from issue_comments where issue_name = (?)");

for (int i=0; i<deleteNames.length;i++) {
//Delete Comments
stmt1.setString(1,deleteNames[i]);
stmt1.executeUpdate();
//Delete Issue
stmt.setString(1,deleteNames[i]);
stmt.executeUpdate();
}

----------------------
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or if there's nothing to be done when no values are selected, you could try:


[ June 20, 2006: Message edited by: Dave Wingate ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic