Originally posted by Nischal Topno:
If a result set is TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE, and if the query selects a DISTINCT, why does the resultset.next() return true even after there are not records. It gives "Invalid cursor state" error.
Say, I have a table MYTABLE with a field MYFIELD with the following data in MYFIELD:
========
NOKIA
ERRICSON
NOKIA
========
The following is my code:
--------------------------------------------------
import java.sql.*;
public class hello {
public static void main (String args[]) {
Connection con=null;
Statement stmt;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbcdbc:Nischal", uid, pwd);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery("SELECT DISTINCT MYFIELD FROM MYTABLE");
while(rs.next()){
System.out.println(rs.getString("MESSAGEID"));
}
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
if (con!=null) {
con.close();
}
}catch(SQLException e) {
e.printStackTrace();
}
}
}
}
--------------------------------------------------
Strangely, if I use TYPE_FORWARD_ONLY, or use SELECT statement without DISTINCT then it works perfectly.
Is there any method to find the number of records fetched in a ResultSet (something like rs.recordcount in ADO/VB6)
Please Help
Nischal
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Originally posted by Nischal Topno:
If a result set is TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE, and if the query selects a DISTINCT, why does the resultset.next() return true even after there are not records. It gives "Invalid cursor state" error.
Say, I have a table MYTABLE with a field MYFIELD with the following data in MYFIELD:
========
NOKIA
ERRICSON
NOKIA
========
The following is my code:
--------------------------------------------------
import java.sql.*;
public class hello {
public static void main (String args[]) {
Connection con=null;
Statement stmt;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbcdbc:Nischal", uid, pwd);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery("SELECT DISTINCT MYFIELD FROM MYTABLE");
while(rs.next()){
System.out.println(rs.getString("MESSAGEID"));
}
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
if (con!=null) {
con.close();
}
}catch(SQLException e) {
e.printStackTrace();
}
}
}
}
--------------------------------------------------
Strangely, if I use TYPE_FORWARD_ONLY, or use SELECT statement without DISTINCT then it works perfectly.
Is there any method to find the number of records fetched in a ResultSet (something like rs.recordcount in ADO/VB6)
Please Help
Nischal
Looky! I'm being abducted by space aliens! Me and this tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|