to use rs.previous() method
you need to have jdk 1.3 in your system
pl check the following code in your system after giving jdbc connections
import java.sql.*;
public class MyConnection
{
Connection con;
MyConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc
dbc:dsnaccess","","");
}
catch(Exception e)
{
System.out.println(" in myconnection.java file " +e);
}
}
}
*********************************************
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class UserSearchMod extends Frame implements ActionListener
{
Label userIDLbl,userNameLbl;
TextField userIDTxt,userNameTxt;
Label lbUser[][];
Checkbox chUser[];
Button searchUser;
ScrollPane spUser;
Panel userPanel,recUserPanel[];
Button previous,next,reset,exit;
MyConnection myCon;
Statement st,st1,st2;
ResultSet rs,rs2;
int i;
boolean nextP,prev,ent;
UserSearchMod()
{
setLayout(null);
myCon = new MyConnection();
try
{
st = myCon.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
st1 = myCon.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
st2 = myCon.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch(Exception e)
{
System.out.println("defining connection objects "+e);
}
userIDLbl = new Label("User ID");
userNameLbl = new Label("User Name");
userIDTxt = new TextField(15);
userNameTxt = new TextField(15);
searchUser = new Button("Search");
previous=new Button("Previous");
next=new Button("Next");
reset=new Button("Reset");
exit = new Button("Exit");
spUser = new ScrollPane();
userPanel = new Panel();
add(userIDLbl);
add(userIDTxt);
add(userNameLbl);
add(userNameTxt);
add(searchUser);
add(spUser);
spUser.add(userPanel);
add(previous);
add(next);
add(reset);
add(exit);
searchUser.addActionListener(this);
previous.addActionListener(this);
next.addActionListener(this);
reset.addActionListener(this);
exit.addActionListener(this);
userIDLbl.setBounds(150,30,50,25);
userIDTxt.setBounds(210,30,100,25);
userNameLbl.setBounds(335,30,65,25);
userNameTxt.setBounds(410,30,100,25);
searchUser.setBounds(550,30,75,25);
spUser.setBounds(50,60,500,200);
previous.setBounds(150,400,75,25);
next.setBounds(250,400,75,25);
reset.setBounds(350,400,75,25);
exit.setBounds(450,400,75,25);
/* previous.setBounds(150,530,75,25);
next.setBounds(250,530,75,25);
reset.setBounds(350,530,75,25);
exit.setBounds(450,530,75,25); */
setSize(600,450);
setLocation(0,0);
show();
}
public void nextRecords()
{
nextP=true;
userPanel.removeAll();
lbUser = new Label[6][5];
userPanel.setLayout(new GridLayout(6,1));
recUserPanel=new Panel[6];
System.out.println("Hello sop from next() before try ");
try
{
System.out.println("Hello sop 1 "+rs.getRow());
while(prev&&i<6)
{
rs.next();
i++;
}
i=0;
System.out.println("Hello sop 2 "+rs.getRow());
if(!rs.isFirst()&&prev)
{
rs.previous();
prev=false;
}
System.out.println("Hello sop 3 "+rs.getRow());
if(ent)
{
do
{
if(rs.isLast())
{
next.setEnabled(false);
}
recUserPanel[i] = new Panel();
recUserPanel[i].setLayout(new GridLayout(1,5));
System.out.println("Hello sop 4 "+rs.getRow());
for(int j=0;j<5;j++)
{
lbUser[i][j] = new Label(rs.getString(j+1));
lbUser[i][j].setSize(75,25);
recUserPanel[i].add(lbUser[i][j]);
}
userPanel.add(recUserPanel[i]);
i++;
}
while( i<6 && rs.next() );
System.out.println("Hello sop 5 "+rs.getRow());
}
else
{
while( i<6 && rs.next() )
{
if(rs.isLast())
{
next.setEnabled(false);
}
recUserPanel[i] = new Panel();
recUserPanel[i].setLayout(new GridLayout(1,5));
for(int j=0;j<5;j++)
{
lbUser[i][j] = new Label(rs.getString(j+1));
lbUser[i][j].setSize(75,25);
recUserPanel[i].add(lbUser[i][j]);
}
userPanel.add(recUserPanel[i]);
i++;
}
}
System.out.println("Hello sop 6 "+rs.getRow());
}
catch(Exception e)
{
System.out.println("Exception in next records () "+e);
}
}
public void prevRecords()
{
prev=true;
ent=true;
System.out.println("Previous..");
userPanel.removeAll();
lbUser = new Label[6][5];
userPanel.setLayout(new GridLayout(6,1));
recUserPanel=new Panel[6];
try
{
while(i>0)
{
rs.previous();
i--;
}
i=5;
while(i>=0 && rs.previous())
{
System.out.println(i);
if(rs.isFirst())
{
previous.setEnabled(false);
}
recUserPanel[i] = new Panel();
recUserPanel[i].setLayout(new GridLayout(1,5));
for(int j=0;j<5;j++)
{
lbUser[i][j] = new Label(rs.getString(j+1));
lbUser[i][j].setSize(75,25);
recUserPanel[i].add(lbUser[i][j]);
}
userPanel.add(recUserPanel[i]);
i--;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void actionPerformed(ActionEvent ae)
{
String sqlString=null;
if(ae.getSource()==searchUser)
{
show();
next.setEnabled(true);
previous.setEnabled(false);
if(!(userIDTxt.getText().equals("") && userNameTxt.getText().equals("")))
{
sqlString = "select * from users where userid like '" + userIDTxt.getText() + "%' and name like '" + userNameTxt.getText() + "%'";
}
if(!(userIDTxt.getText().equals("")) && userNameTxt.getText().equals(""))
{
sqlString = "select * from users where userid like '" + userIDTxt.getText() + "%'";
}
if(userIDTxt.getText().equals("") && !(userNameTxt.getText().equals("")))
{
sqlString = "select * from users where name like '" + userNameTxt.getText() + "%'";
}
if(userIDTxt.getText().equals("") && userNameTxt.getText().equals(""))
{
sqlString = "select * from users";
}
show();
try
{
if(nextP)
{
rs.close();
nextP=false;
}
rs = st.executeQuery(sqlString);
nextP=true;
nextRecords();
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println(sqlString);
show();
}
if(ae.getSource()==next)
{
previous.setEnabled(true);
nextRecords();
show();
}
if(ae.getSource()==previous)
{
next.setEnabled(true);
prevRecords();
show();
}
if(ae.getSource()==reset)
{
userPanel.removeAll();
userIDTxt.setText("");
userNameTxt.setText("");
}
if(ae.getSource()==exit)
{
System.exit(0);
}
}
public static void main(String args[])
{
new UserSearchMod();
}
}
******+
just try this program
and give me feed back
i am facing the pblm with sql server in the same situation even if i use jdk 1.3
help me
bye