Results 1 to 9 of 9
Thread: Problem with ResultSet
- 01-23-2010, 12:30 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 10
- Rep Power
- 0
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
- 01-23-2010, 03:50 PM #2
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 ?
- 01-25-2010, 07:54 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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).
- 01-25-2010, 08:59 AM #4
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:cool:
- 01-25-2010, 08:39 PM #5
Member
- Join Date
- Jan 2010
- Posts
- 10
- Rep Power
- 0
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.
- 01-25-2010, 11:07 PM #6
.. ok, what is the exception.
- 01-26-2010, 10:43 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Are you really eating all Exceptions there?
That's not good.
- 01-26-2010, 05:39 PM #8
Member
- Join Date
- Jan 2010
- Posts
- 10
- Rep Power
- 0
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.
- 01-27-2010, 08:49 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Problem when adding values of the ResultSet to a AbstractTableModel
By Azuxard in forum AWT / SwingReplies: 4Last Post: 04-01-2009, 02:03 AM -
Problem with resultSet.updateNString and rowSet.updateNString
By hungleon88 in forum JDBCReplies: 0Last Post: 01-07-2009, 11:44 AM -
ResultSet.updateRow() problem
By kvikas in forum Advanced JavaReplies: 1Last Post: 04-22-2008, 03:11 AM -
problem with ResultSet.updateRow()
By kvikas in forum New To JavaReplies: 0Last Post: 04-14-2008, 10:00 AM -
ResultSet example
By Java Tip in forum Java TipReplies: 0Last Post: 01-20-2008, 08:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks