Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-23-2010, 01:30 AM
Member
 
Join Date: Jan 2010
Posts: 8
Rep Power: 0
flaquitqm is on a distinguished road
Default Problem with ResultSet
Hello everybody:
I have a problem with a result set too. ResultSet doesn't get all data store in my table, the cursor start in the third row, so I miss rows 1 and 2. How can I put the cursor in the first row in a TYPE_FORWARD_ONLY result set? Here is my code:

TDepartamento dpto = new TDepartamento();
ArrayList<TDepartamento> listaDptos = new ArrayList<TDepartamento>();
try {
sql = "Select * from Departamento order by idDpto";
statement = TConexion.getConexion().prepareStatement(sql);

ResultSet rs = statement.executeQuery();
while (rs.next()){
dpto.setCodigo(rs.getInt("CodigoDpto"));
dpto.setDpto(rs.getString("Dpto"));
listaDptos.add(dpto);
}


return listaDptos;
}

sorry for my english and thank you
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-23-2010, 04:50 PM
travishein's Avatar
Senior Member
 
Join Date: Sep 2009
Location: Canada
Posts: 355
Rep Power: 1
travishein is on a distinguished road
Default
I don't see how this would cause the result to start off on not the first row.

Only idea is if you are not closing the statement, maybe your custom data accessor is reusing the same open connection, and if it has a reference to the statement in some kind of not threadsafe manner,then maybe the same result set is being read by more than one client at once ?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-25-2010, 08:54 AM
Senior Member
 
Join Date: Apr 2009
Posts: 944
Rep Power: 1
Tolls is on a distinguished road
Default
Even so, unless that's some sort of non=standard result set there is no way that code there will skip lines (and I wish you'd put a link to this post in the other one you hijacked).
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-25-2010, 09:59 AM
RamyaSivakanth's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Chennai
Posts: 589
Rep Power: 1
RamyaSivakanth is on a distinguished road
Default
As per the code you put,its not a scrollable ResultSet.There is no chance as you mentioned record got missed.By default cursor will point before first row and go on travese till the end.

My doubt is whether any where checking sake have u put "rs.next()"? Once if u use rs.next(),then there is a chance that traversal as happened already...just post your complete code.
__________________
Ramya
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-25-2010, 09:39 PM
Member
 
Join Date: Jan 2010
Posts: 8
Rep Power: 0
flaquitqm is on a distinguished road
Default
Thanks to all of you for help me. Here is the complete code:

public ArrayList<TDepartamento> GetDepartamentos() throws SQLException{

ArrayList<TDepartamento> listaDptos = new ArrayList<TDepartamento>();
try {
sql = "Select * from Departamento";

PreparedStatement statement = TConexion.getConexion().prepareStatement(sql);

ResultSet rs = statement.executeQuery();

while (rs.next()){
int t = rs.getRow();
TDepartamento dpto = new TDepartamento();

dpto.setCodigo(rs.getInt("CodigoDpto"));
dpto.setId(rs.getInt("IdDpto"));
dpto.setDpto(rs.getString("Dpto"));

listaDptos.add(dpto);
}

return listaDptos;


} catch (Exception e) {
// TODO: handle exception
return listaDptos;
}
}

I have the same problem with other resultset in other procedure.
when I execute the sql code directly in my database I get row, son the sql statement is ok, but my resultset doesn't have that row and I get an exception.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-26-2010, 12:07 AM
travishein's Avatar
Senior Member
 
Join Date: Sep 2009
Location: Canada
Posts: 355
Rep Power: 1
travishein is on a distinguished road
Default
.. ok, what is the exception.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-26-2010, 11:43 AM
Senior Member
 
Join Date: Apr 2009
Posts: 944
Rep Power: 1
Tolls is on a distinguished road
Default
Are you really eating all Exceptions there?
That's not good.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-26-2010, 06:39 PM
Member
 
Join Date: Jan 2010
Posts: 8
Rep Power: 0
flaquitqm is on a distinguished road
Default
The exception tells me that resultset is close. Now everything is working, I didn't get that exception, but I don't know why it was happening.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 01-27-2010, 09:49 AM
Senior Member
 
Join Date: Apr 2009
Posts: 944
Rep Power: 1
Tolls is on a distinguished road
Default
I didn't understand any of that, sorry.

What does your code look like now, and what problems/errors/exceptions are you getting, and where?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem when adding values of the ResultSet to a AbstractTableModel Azuxard AWT / Swing 4 04-01-2009 03:03 AM
Problem with resultSet.updateNString and rowSet.updateNString hungleon88 Database 0 01-07-2009 12:44 PM
ResultSet.updateRow() problem kvikas Advanced Java 1 04-22-2008 04:11 AM
problem with ResultSet.updateRow() kvikas New To Java 0 04-14-2008 11:00 AM
ResultSet example Java Tip Java Tips 0 01-20-2008 09:59 AM


All times are GMT +2. The time now is 06:46 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org