zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    网站性能优化分类总结
    关于高度塌陷问题解决方法
    语义化HTML
    CSS命名规范
    linux开机过程
    Linux--sed命令
    博客声明
    linux-- grep命令
    pyinstaller使用-python项目转换成exe可执行文件
    python导出开发环境
  • 原文地址:https://www.cnblogs.com/donghb/p/7479418.html
Copyright © 2011-2022 走看看