Solved

Why empty resultset ?????-URGENT

Posted on 2003-12-11
19
371 Views
Last Modified: 2010-04-01
hi,

skill=volgetSKILL();
if(skill!=null&& skill.length() != 0 &&!skill.equals("")){
//insert data;
}

Problem is empty resultset is get entered, what to do  


thanks
0
Comment
Question by:Jasbir21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
  • +1
19 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 9920694
problem in somewhere else, post your real code.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9920713
That sounds like you're in a bad mood kenneth ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9920751
if(skill!=null&& skill.length() != 0 &&!skill.equals("")){
     out.println( "Adding '" + skill + "'<br/>" ) ;
//insert data;
}

what does it print?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:kennethxu
ID: 9920786
No, I'm not :-(
Could it be the cause that English is my second language?
I'm working on projects in same time, that might be another reason that I didn't pay attention to proper phrase the sentence. Sorry Jasbir21.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9920898
>> Could it be the cause that English is my second language?

I'm sorry kenneth.  I was only joking.  For the record, I haven't seen you be anything other than patient and helpful :-)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9921038
Hi Jim, no sorry. In fact, I really thank you for reminding me on that. Look, Tim was obviously taking a much better approach then I did :-)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9921063
Just for info:

if(skill!=null&& skill.length() != 0 &&!skill.equals(""))

could be shortened to:

if(skill!=null && skill.length() > 0)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9921168
and lengthened to:

if( skill == null ? false : skill.length() > 0 ? true : false )

hehehehehe
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9921171
(sorry) :-(
0
 

Author Comment

by:Jasbir21
ID: 9924882
hi,
sorry for the late response, we had leave the lab because to late .Now, I can enter again:

the code is :
with println, i see empty string get inserted:...

if(skill!=null && skill.length() > 0)
 
{
 
out.println( "Adding '" + skill + "'<br/>" ) ;

  StringTokenizer st = new StringTokenizer(skill,",");
  String[] ar = new String[st.countTokens()];
  int i=0;


if(st.hasMoreTokens()){

while(st.hasMoreTokens())
 {
  ar[i]=st.nextToken();

 


 String query = "insert into userskills(username,skill) values(?,?)";
  prep3=connection.prepareStatement(query);
  prep3.setString(1,username);
  prep3.setString(2,ar[i]);
  prep3.executeUpdate();
   i++;

}

}

          }//if


prep3.close();

.....

it works like this:
In volunteer.jsp,you have this:
<textarea type="text" name="skill" rows="5"  cols="15" wrap readonly >
</textarea>
and this value is assinged to bean and directed to DB.jsp which does inserting.
the code skill!=null..........is in DB.jsp


thanks


0
 

Author Comment

by:Jasbir21
ID: 9924933
i forgot to say in volunteer.jsp , it is assigned like this:

String  skill=vol.getSkill();

I able to delete skill in volunteer.jsp and when i mysql database, i see in table userskills in database, skill really get deleted, not any empty strings.

But when i press button submit , then only empty string gets inserted.

Thansk you
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9924934
Unless you are using the array "ar" for some other purpose, it's not required, you could change:

if(st.hasMoreTokens()){

while(st.hasMoreTokens())
 {
  ar[i]=st.nextToken();
  String query = "insert into userskills(username,skill) values(?,?)";
  prep3=connection.prepareStatement(query);
  prep3.setString(1,username);
  prep3.setString(2,ar[i]);
  prep3.executeUpdate();
   i++;
}

to:

if(st.hasMoreTokens()){

while(st.hasMoreTokens())
 {
  String query = "insert into userskills(username,skill) values(?,?)";
  prep3=connection.prepareStatement(query);
  prep3.setString(1,username);
  prep3.setString(2, st.nextToken());
  prep3.executeUpdate();
}

However, this doesn't explain why you're getting empty strings inserted into the database.

Could you just confirm that you see the following:

Adding ''

0
 
LVL 15

Expert Comment

by:jimmack
ID: 9924940
If you see something like:

Adding ' '

you might want to consider changing:

String  skill=vol.getSkill();

to

String  skill=vol.getSkill().trim();
0
 

Author Comment

by:Jasbir21
ID: 9924961
yah, i get something like this ' ', i  change now
0
 

Author Comment

by:Jasbir21
ID: 9924992
i got error:

java.lang.NullPointerException
      org.apache.jsp.jsp2.volunteerupdateDB_jsp._jspService(volunteerupdateDB_jsp.java:189)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

maybe this is because, the skill value needs not to be entered, i think,not sure
thanks
0
 

Author Comment

by:Jasbir21
ID: 9925002
i mean, the skill textarea, need not to be entered, i mean, if user never enter skill textarea, it is ok.

i hope i not confusing with bad english
0
 
LVL 15

Accepted Solution

by:
jimmack earned 60 total points
ID: 9925015
OK.  I don't *think* that should be too much of a problem.  Remove the .trim() you have just added and move it here instead:

  StringTokenizer st = new StringTokenizer(skill.trim(),",");

At least when you get to this line, you've already checked for null.
0
 

Author Comment

by:Jasbir21
ID: 9925092
Thanks very much,it works
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9927516
;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exception creating bean of class 5 219
xjc and jaxb 2 95
I am having a difficulty creating a responsive Page for my website. 10 87
web application structure 18 111
Direct mail marketing is the act of mailing materials straight to prospective customers. This wide form of marketing is one of the oldest methods of communicating with a geographic based demographic. So is it useful in 2017 and beyond?
After-hours service is a fact of life for most MSPs. While not the most pleasant aspect of the job, there are ways to make after-hours servicing a more profitable and organized enterprise.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question