aspose file tools*
The moose likes JDBC and the fly likes Navigating data using JDBC and SQLServer 2005 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Navigating data using JDBC and SQLServer 2005" Watch "Navigating data using JDBC and SQLServer 2005" New topic
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
232

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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
232

Also see why you should elaborate on what "not working" means
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Navigating data using JDBC and SQLServer 2005