import java.sql.*;
import java.io.*;
class scrlablrs
{
public static void main(String ar[])throws ClassNotFoundException, SQLException, IOException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:dbaccess","my","asa");
System.out.println("\nConnection Established\n");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("select * from student");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Database Menu");
int ch;
do
{
System.out.println("\n1. Move to the next Record.\n2. Move to the first Record.\n3. Move to the Previous Record.\n4. Move to the last Record.\n5. Exit.\n\nEnter Choice: ");
ch = Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
if(rs.next())
System.out.println("\n\tNext Record: Roll No: "+ rs.getString(1) + "\n\tSubject: " + rs.getString(2) + "\n\tPercentage: " + rs.getString(3));
break;
case 2:
if(rs.first())
System.out.println("\n\tFirst Record : Roll No: "+ rs.getString(1) + "\n\tSubject: " + rs.getString(2) + "\n\tPercentage: " + rs.getString(3));
break;
case 3:
if (rs.previous())
System.out.println("\n\tPrevious Record : Roll No: "+ rs.getString(1) + "\n\tSubject: " + rs.getString(2) + "\n\tPercentage: " + rs.getString(3));
break;
case 4:
if(rs.last())
System.out.println("\n\tLast Record : Roll No: "+ rs.getString(1) + "\n\tName: " + rs.getString(2) + "\n\tMarks: " + rs.getString(3));
break;
case 5:
System.exit(0);
break;
}
}
while(ch!=5);
}
}
Post a Comment