package sixmysql;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.Scanner;
import com.mysql.jdbc.Driver;
public class sixmysql {
static String driver;
static String name;
static String url;
static String password;
static {
Properties pro=new Properties();
InputStream in=sixmysql.class.getClassLoader().getResourceAsStream("db.properties");
try {
pro.load(in);
url=pro.getProperty("url");
driver=pro.getProperty("driver");
name=pro.getProperty("name");
password=pro.getProperty("password");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException {
int lint;
int page;
int p ;
try {
Class.forName(driver);
Connection conn=DriverManager.getConnection(url,name,password);
System.out.println("请输入需要查询的页数");
Scanner in1=new Scanner(System.in);
page=in1.nextInt();
System.out.println(page);
System.out.println("请输入需要查询的行数");
Scanner in2=new Scanner(System.in);
lint=in2.nextInt();
System.out.println(page);
p = (page-1)*lint;
String sql="SELECT * FROM `yrd_users` limit ?,?;";
PreparedStatement psmt=conn.prepareStatement(sql);
psmt.setInt(1, p);
psmt.setInt(2,lint);
ResultSet res=psmt.executeQuery();
while(res.next()) {
String phone=res.getString("phone");
System.out.println(phone);
}
System.out.println();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}