Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

no data found error

 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String values = "",data = "",Machineip = "";
List list = myclass.listing();
Iterator it = list.iterator();
String value = "";
while(it.hasNext())
{
value = it.next().toString();
%>
<td><%=value%></td>
<%
java.sql.ResultSet res = myclass.selectQuery();
while(res.next())
{
data = res.getString(value);
//if(value.equals("Machine_IP"))Machineip = res.getString(value);

}}

this code gives a no data found error...even though there is data ... can anyone help?
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe show us what listing and selectQuery is doing. Using ResultSet as you do is not good idea. Move your database work to some java class and all the logic do there and for jsp prepare just data to show.
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a table in which the column no can change. now i need to display all the values in the screen. which collection shud i use. plz its urgent
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First create the bean which will hold the data from the table, than put beans in some collection (ArrayList for example) and iterate it on the jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which collection shud i use. plz its urgent


Betsy, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
Forum Bartender
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for using abbreviations but i am in need of knowing which collection will help me to access the data.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on structure of data. Can you give some example about the data? But try to think about the bean as a holder of data please
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Ulicny:
But try to think about the bean as a holder of data please


Yes. A collection of your VOs (Value Objects). Value Object also known as Transfer Object.
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what if the values in the value objects changes ? for example if i try to alter the table by adding a column. the bean will have to incorporate a new getter/setter. how can this be incorporated ??
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't the return from it.next() be cast to String?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roger Chung-Wee:
Shouldn't the return from it.next() be cast to String?
Why? Object has a toString() method, so a cast would surely be unnecessary.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a cast is necessary because the toString method for class Object might return something like this.

<classname>@111f71

So, when the variable value refers to a String like "<classname>@111f71", then it is no wonder that this line of code gives the wrong result.

 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roger Chung-Wee:
I think a cast is necessary because the toString method for class Object might return something like this.

<classname>@111f71[/CODE]
Have you tried it? Surely it will use runtime binding and invoke whichever toString() method that particular class has implemented? [That's what is called polymorphism.] If you haven't overridden the toString() method, well that's different.

:p
 
Srilakshmi Vara
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are not sure of number of columns, you cannot create a collection of objects becuase the object need to be changed every time a DB change occurs, instead you can store them as ArrayList of ArrayList. But this works only if you are not applying any logic to the data.

HTH
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know, it really helps when people can remember the basics of Java before making posts. I am ashamed to say that I was completely wrong.

it.next().toString(); will indeed return the String value.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everybody does that sort of thing . . . don't worry about it
 
Paul Clapham
Sheriff
Posts: 21133
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roger Chung-Wee:
You know, it really helps when people can remember the basics of Java before making posts. I am ashamed to say that I was completely wrong.
But you learned something that you hadn't learned correctly before. It's a bonus when more than one person learns something from a thread.
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone help me in my query please
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Betsy Camel:
can anyone help me in my query please


You need to make change in your code.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Break the problem into two parts. Firstly, what does this do when you run it?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic