• sql语句查询数据库案例


    package com.hanqi.test;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import com.hanqi.util.JdbcConnectionUtil;
    
    public class Test {
        
        private static Connection con; //链接数据库
        private static PreparedStatement pste;// 执行sql语句
        private static ResultSet rs; //执行返回结果
        
        public static void main(String[] args) {
            init();
            String sql = "select * from appuser";
            try {
                pste = con.prepareStatement(sql);// 执行sql语句
                rs = pste.executeQuery();//执行完的返回结果
                
                while(rs.next()) {
                    System.out.println(rs.getInt("id"));
                    System.out.println(rs.getString("username"));
                    System.out.println(rs.getString("password"));
                    System.out.println(rs.getString("realname"));
                    System.out.println(rs.getDate("createtime"));
                    System.out.println("================================");
                }
                
            } catch (SQLException e) {
                e.printStackTrace();
            }
            close();
        }
        
        public static void init() {
            con = JdbcConnectionUtil.getConnection();
        }
        
        public static void close() {
            JdbcConnectionUtil.destroy(con,pste,rs);
        }
    }
  • 相关阅读:
    noip2018练习总结
    东方CannonBall (概率DP)
    数论
    逆序对
    USACO5.3 校园网Network of Schools(Tarjan缩点)
    USACO09FEB 改造路Revamping Trails(分层图模板)
    Comet OJ模拟赛 Day1
    Tarjan模板
    NOIP 天天爱跑步(树上差分)
    树上差分
  • 原文地址:https://www.cnblogs.com/donghb/p/7479418.html
Copyright © 2020-2023  润新知