File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Navigating data using JDBC and SQLServer 2005

 
Soumya Rout
Ranch Hand
Posts: 49
Java Java ME Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33691
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Soumya,
Why not write a SQL query that returns the first 2 rows and another that returns the last two rows?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33691
316
Eclipse IDE Java VI Editor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic