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);
        }
    }
  • 相关阅读:
    systemtap没找到函数变量
    systemtap get var of the tracepoing
    如何在tracepoint上注册函数
    stap中的entry函数
    stap用法
    在submit_bio处使用stapn
    巴达努斯
    perf事件的切换
    perf原理再看
    内存回收的阈值
  • 原文地址:https://www.cnblogs.com/donghb/p/7479418.html
Copyright © 2011-2022 走看看