Java Code for implementation of Scrollable Resultset(movenext,moveprevious,movefirst,movelast)
import java.io.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class slip2 extends Frame implements ActionListener
{
Button b1,b2,b3,b4;
TextField t1,t2,t3,t4;
Label l1,l2,l3,l4;
Connection con=null;
Statement st=null;
ResultSet rs=null;
slip2()
{ try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:emp1");
st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery("select * from emp");
} catch(Exception ee) {
System.out.println("fsfsddsf"+ee);
}
l1=new Label("Enter No");
l2=new Label("Enter Name");
l3=new Label("Enter Salary");
t1=new TextField();
t2=new TextField();
t3=new TextField();
b1=new Button("First");
b2=new Button("Last");
b3=new Button("Next");
b4=new Button("Previous");
setLayout(null);
add(l1);
l1.setBounds(10,50,100,30);
add(t1);
t1.setBounds(120,50,150,30);
add(l2);
l2.setBounds(10,100,100,50);
add(t2);
t2.setBounds(120,100,150,30);
add(l3);
l3.setBounds(10,150,100,50);
add(t3);
t3.setBounds(120,150,150,30);
add(b1);
b1.setBounds(20,200,60,30);
add(b2);
b2.setBounds(80,200,60,30);
add(b3);
b3.setBounds(140,200,60,30);
add(b4);
b4.setBounds(200,200,60,30);
setVisible(true);
setSize(500,500);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:emp1");
} catch(Exception ee)
{ System.out.println("fsfsddsf"+ee);
}
if(str.equals("First"))//function for Move First
{ try
{rs.first();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
} catch(Exception ee)
{ System.out.println(ee);
} }
if(str.equals("Last"))//function for Move Last
{ try
{rs.last();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
} catch(Exception ee) {
System.out.println(ee);
} }
if(str.equals("Next"))/function for Move Next
{ try {
rs.next();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
} catch(Exception ee) {
System.out.println(ee);
} }
if(str.equals("Previous"))//function for Move Previous
{ try
{ rs.previous();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
}
catch(Exception ee)
{
System.out.println(ee);
} } }
public static void main(String arg[])
{
new slip2();
}
}
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
class slip2 extends Frame implements ActionListener
{
Button b1,b2,b3,b4;
TextField t1,t2,t3,t4;
Label l1,l2,l3,l4;
Connection con=null;
Statement st=null;
ResultSet rs=null;
slip2()
{ try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:emp1");
st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery("select * from emp");
} catch(Exception ee) {
System.out.println("fsfsddsf"+ee);
}
l1=new Label("Enter No");
l2=new Label("Enter Name");
l3=new Label("Enter Salary");
t1=new TextField();
t2=new TextField();
t3=new TextField();
b1=new Button("First");
b2=new Button("Last");
b3=new Button("Next");
b4=new Button("Previous");
setLayout(null);
add(l1);
l1.setBounds(10,50,100,30);
add(t1);
t1.setBounds(120,50,150,30);
add(l2);
l2.setBounds(10,100,100,50);
add(t2);
t2.setBounds(120,100,150,30);
add(l3);
l3.setBounds(10,150,100,50);
add(t3);
t3.setBounds(120,150,150,30);
add(b1);
b1.setBounds(20,200,60,30);
add(b2);
b2.setBounds(80,200,60,30);
add(b3);
b3.setBounds(140,200,60,30);
add(b4);
b4.setBounds(200,200,60,30);
setVisible(true);
setSize(500,500);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:emp1");
} catch(Exception ee)
{ System.out.println("fsfsddsf"+ee);
}
if(str.equals("First"))//function for Move First
{ try
{rs.first();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
} catch(Exception ee)
{ System.out.println(ee);
} }
if(str.equals("Last"))//function for Move Last
{ try
{rs.last();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
} catch(Exception ee) {
System.out.println(ee);
} }
if(str.equals("Next"))/function for Move Next
{ try {
rs.next();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
} catch(Exception ee) {
System.out.println(ee);
} }
if(str.equals("Previous"))//function for Move Previous
{ try
{ rs.previous();
t1.setText(Integer.toString(rs.getInt(1)));
t2.setText(rs.getString(2));
t3.setText(Integer.toString(rs.getInt(3)));
System.out.println("Saved");
}
catch(Exception ee)
{
System.out.println(ee);
} } }
public static void main(String arg[])
{
new slip2();
}
}
Comments
Post a Comment