• mysql 分页查询的标准写法


    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();
      }
    }

    }

  • 相关阅读:
    PackageManagerService.java 构造函数的 分析
    如何把APK应用装到只读ROM
    对apk包进行odex优化的目的
    如何把APK应用装到只读ROM
    php学习笔记面向对象中[接口]与[多态性]的应用
    php学习笔记[PHP面向对象的程序设计]
    PHP学习之路(二)让我们开始环境搭建(Windows篇)
    php设计模式 Command(命令模式)
    php数组指针探究
    yii框架学习笔记
  • 原文地址:https://www.cnblogs.com/czb529514/p/8031755.html
Copyright © 2020-2023  润新知