package com.project;import java.sql.*;import java.util.Scanner;public class Test { private static String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; private static String url="jdbc:sqlserver://localhost;DataBaseName=aa"; public static void main(String[] args){ Scanner sc=new Scanner(System.in); try { Class.forName(driver); Connection con=DriverManager.getConnection(url,"sa","123"); PreparedStatement pst=con.prepareStatement("select * from tb",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet res=pst.executeQuery(); System.out.println("学生编号\t"+"姓名\t"); int i=0; while(res.next()){ System.out.println(res.getString(1)+"\t"+res.getString(2)+"\t"); System.out.println("-----------------"); i++; if(i==3){ System.out.println("首页【F】 上一页【p】 下一页【n】 尾页【l】\n请选择操作:"); String xz=sc.next();//接收选择 i=0; if(xz.equals("f")){ res.first(); res.previous(); } if(xz.equals("p")){ for(int j=0;j<6;j++) res.previous();//移动到此ResultSet对象的上一行 i=0; } if(xz.equals("l")){ res.last(); for(int j=0;j<3;j++) res.previous(); i=0; } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }}
数据库
create database aause aacreate table tb( id int, name varchar(50),)insert tb values (1,'aa')insert tb values (2,'aa')insert tb values (3,'aa')insert tb values (4,'aa')insert tb values (5,'aa')insert tb values (6,'aa')insert tb values (7,'aa')insert tb values (8,'aa')insert tb values (9,'aa')insert tb values (10,'aa')insert tb values (11,'aa')insert tb values (12,'aa')insert tb values (13,'aa')insert tb values (14,'aa')insert tb values (15,'aa')select *from tbdelete tb where id=10
最后导入相对应连接数据的包