| Author |
Navigating data using JDBC and SQLServer 2005
|
Soumya Rout
Ranch Hand
Joined: Aug 06, 2009
Posts: 49
|
|
Hi,
I want to navigate data from SQLServer database and I have retrieved the first and last values but i want to retrieve the next and previous values after first row and last row respectively.
for retriveing previous value i have written the following code...
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("Jdbc:Odbc:javadsn","sa","sql");
String query="select * from Login ";
st=con.createStatement(rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_READ_ONLY);
rs=st.executeQuery(query);
int rowno=rs.getRow();
String val1,val2;
val1= val2= null;
if(!rs.isFirst())
{
rowno--;
rs.absolute(rowno);
val1= rs.getString("Uname").trim();
val2= rs.getString("Pass").trim();
System.out.println("Working !!");
}
jTextField2.setText(val1);
jTextField3.setText(val2);
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, ex.toString());
}
but its not woking and i have also tried for next value
by changing the row-- to row++ and (!rs.isLast) but its not working pleasehelp....
thnx in advance
Regards som
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
Soumya,
Why not write a SQL query that returns the first 2 rows and another that returns the last two rows?
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
|
Also see why you should elaborate on what "not working" means
|
 |
 |
|
|
subject: Navigating data using JDBC and SQLServer 2005
|
|
|