This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

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: 30136
    
150

Also see why you should elaborate on what "not working" means
 
 
subject: Navigating data using JDBC and SQLServer 2005
 
Similar Threads
New at this...need help
Rendered property doubt
jsp sending values
Setting the attribute
Split a string of data into array elements