Share on Google+Share on Google+

Anoop Kumar
Java Program
2 Answer(s)      7 years ago
Posted in : JDBC

Ads

View Answers

August 28, 2009 at 3:07 PM


Hi Friend,

Try the following code:

import java.sql.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;

public class NavigateData extends JFrame{
JTextField text1,text2,text3,text4;
JLabel label1,label2,label3,label4;
int count=0;
JButton nextRecord,previousRecord,firstRecord,lastRecord;
static JPanel panel;
public static void main(String []args)throws Exception{
NavigateData navigate=new NavigateData();
navigate.setSize(350,200);
navigate.setVisible(true);
navigate.add(panel);
}
public NavigateData(){
//count=-1;
text1=new JTextField();
text2=new JTextField();
text3=new JTextField();
text4=new JTextField();
label1=new JLabel("Employee ID");
label2=new JLabel("Employee Name");
label3=new JLabel("Employee Address");
label4=new JLabel("Employee Salary");
nextRecord=new JButton("Next");
previousRecord=new JButton("Previous");
firstRecord=new JButton("First");
lastRecord=new JButton("Last");
panel=new JPanel(new GridLayout(6,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
panel.add(nextRecord);
panel.add(previousRecord);
panel.add(firstRecord);
panel.add(lastRecord);

nextRecord.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
count++;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("Select * from Employee");
String id="",name="",address="",salary="";
for(int i=0;i<count;i++){
if(rs.next()){
id=Integer.toString(rs.getInt("emp_id"));
name=rs.getString("emp_name");
address=rs.getString("emp_address");
salary=Integer.toString(rs.getInt("emp_salary"));
}
text1.setText(id);
text2.setText(name);
text3.setText(address);
text4.setText(salary);
}
}
catch(Exception ex){}
}
});


August 28, 2009 at 3:08 PM


continue...

previousRecord.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
count--;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("Select * from Employee");
String id="",name="",address="",salary="";
for(int i=0;i<count;i++){
if(rs.next()){
id=Integer.toString(rs.getInt("emp_id"));
name=rs.getString("emp_name");
address=rs.getString("emp_address");
salary=Integer.toString(rs.getInt("emp_salary"));
}
text1.setText(id);
text2.setText(name);
text3.setText(address);
text4.setText(salary);
}
}
catch(Exception ex){}
}
});

firstRecord.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("Select * from Employee");
String id="",name="",address="",salary="";
if(rs.next()){
id=Integer.toString(rs.getInt("emp_id"));
name=rs.getString("emp_name");
address=rs.getString("emp_address");
salary=Integer.toString(rs.getInt("emp_salary"));
}
text1.setText(id);
text2.setText(name);
text3.setText(address);
text4.setText(salary);

}
catch(Exception ex){}
}

});



lastRecord.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("SELECT TOP 1 emp_id, emp_name, emp_address,emp_salary from Employee ORDER BY emp_id DESC");
String id="",name="",address="",salary="";
while(rs.next()){
id=Integer.toString(rs.getInt("emp_id"));
name=rs.getString("emp_name");
address=rs.getString("emp_address");
salary=Integer.toString(rs.getInt("emp_salary"));
}
text1.setText(id);
text2.setText(name);
text3.setText(address);
text4.setText(salary);
}
catch(Exception ex){}

}
});
}
}

Thanks









Related Tutorials/Questions & Answers:
java program for
java program for   java program for printing documents,images and cards
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
Advertisements
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
java program
java program  write a program to print 1234 567 89 10
java program
java program  Write a java program to do matrix addition operation On two given matrices
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix
java program
java program  Write a program to create an applet and display The message "welcome to java
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write java program for constructor,overriding,overriding,exception handling
java program
java program  hi friends how to make a java program for getting non prime odd numbers in a given series
java program
java program  Write a program to demonstrate the concept of various possible exceptions arising in a Java Program and the ways to handle them.  ... in Java
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program  write a program to create text area and display the various mouse handling events
java program
java program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
program in java
program in java  write a reverse program in java using string buffer.the input and out put as follows. input- hi good mornig out put-ih doog ginrom
Java program
Java program  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
java program
java program  . Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program  . Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
java program
java program  Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program   A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A java program to display above triangle
java program
java program  write a program to read 10 numbers from user and store it in a array. display the maximum n minimum number in the array
java program
java program  write a program to create server and client such that server receives data from client using BuuferedReader and sends reply to client using PrintStream
java program
java program  i want a applet program that accepts two input strings using tag and concatenate the strings and display it in status window. please give mi he code for this in core java
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  i want a applet program that accepts two input strings using tag and concatenate the strings and display it in status window. please give mi he code for this in core java
java program
java program  i want a applet program that accepts two input strings using tag and concatenate the strings and display it in status window. please give mi he code for this in core java
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads