• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Navigating data using JDBC and SQLServer 2005

 
Ranch Hand
Posts: 49
Netbeans IDE Java ME Java
  • 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

 
author & internet detective
Posts: 39343
755
Eclipse IDE VI Editor Java
  • 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
Posts: 39343
755
Eclipse IDE VI Editor Java
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!