Jasbir21
asked on
Why empty resultset ?????-URGENT
hi,
skill=volgetSKILL();
if(skill!=null&& skill.length() != 0 &&!skill.equals("")){
//insert data;
}
Problem is empty resultset is get entered, what to do
thanks
skill=volgetSKILL();
if(skill!=null&& skill.length() != 0 &&!skill.equals("")){
//insert data;
}
Problem is empty resultset is get entered, what to do
thanks
problem in somewhere else, post your real code.
That sounds like you're in a bad mood kenneth ;-)
if(skill!=null&& skill.length() != 0 &&!skill.equals("")){
out.println( "Adding '" + skill + "'<br/>" ) ;
//insert data;
}
what does it print?
out.println( "Adding '" + skill + "'<br/>" ) ;
//insert data;
}
what does it print?
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.
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.
>> 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 :-)
I'm sorry kenneth. I was only joking. For the record, I haven't seen you be anything other than patient and helpful :-)
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 :-)
Just for info:
if(skill!=null&& skill.length() != 0 &&!skill.equals(""))
could be shortened to:
if(skill!=null && skill.length() > 0)
if(skill!=null&& skill.length() != 0 &&!skill.equals(""))
could be shortened to:
if(skill!=null && skill.length() > 0)
and lengthened to:
if( skill == null ? false : skill.length() > 0 ? true : false )
hehehehehe
if( skill == null ? false : skill.length() > 0 ? true : false )
hehehehehe
(sorry) :-(
ASKER
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.prepareSt atement(qu ery);
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
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)
prep3=connection.prepareSt
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
ASKER
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
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
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.prepareSt atement(qu ery);
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.prepareSt atement(qu ery);
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 ''
if(st.hasMoreTokens()){
while(st.hasMoreTokens())
{
ar[i]=st.nextToken();
String query = "insert into userskills(username,skill)
prep3=connection.prepareSt
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)
prep3=connection.prepareSt
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 ''
If you see something like:
Adding ' '
you might want to consider changing:
String skill=vol.getSkill();
to
String skill=vol.getSkill().trim( );
Adding ' '
you might want to consider changing:
String skill=vol.getSkill();
to
String skill=vol.getSkill().trim(
ASKER
yah, i get something like this ' ', i change now
ASKER
i got error:
java.lang.NullPointerExcep tion
org.apache.jsp.jsp2.volunt eerupdateD B_jsp._jsp Service(vo lunteerupd ateDB_jsp. java:189)
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:133 )
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 856)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 11)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:301)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:248)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 856)
maybe this is because, the skill value needs not to be entered, i think,not sure
thanks
java.lang.NullPointerExcep
org.apache.jsp.jsp2.volunt
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
maybe this is because, the skill value needs not to be entered, i think,not sure
thanks
ASKER
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
i hope i not confusing with bad english
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much,it works
;-)