zoukankan      html  css  js  c++  java
  • 查询数据

    package cn.fly;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import org.apache.log4j.Logger;
    
    /**
     * 更新数据
     * 
     * @author ASUS
     * 
     */
    public class Query {
        private static Logger logger = Logger.getLogger(Test1.class.getName());
    
        public static void main(String[] args) {
            Connection conn = null;
            Statement stat = null;
            ResultSet rs = null;
            // 1.加载驱动
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                logger.error(e);
            }
            // 2.建立连接
            try {
                conn = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/epet", "root", "root");
                // 更新狗狗信息到数据库
                stat = conn.createStatement();
                rs = stat.executeQuery("select * from dog");
                System.out.println("		狗狗信息列表");
                System.out.println("编号	姓名	健康值	亲密度	品种");
                while (rs.next()) {
                    System.out.print(rs.getInt(1) + "	");
                    System.out.print(rs.getString(2) + "	");
                    System.out.print(rs.getInt(3) + "	");
                    System.out.print(rs.getInt(4) + "	");
                    System.out.println(rs.getString(5));
                }
                logger.info("查询成功~~~");
            } catch (SQLException e) {
                logger.error(e);
            } finally {
                // 3.关闭连接
                if (stat != null) {
                    try {
                        stat.close();
                    } catch (SQLException e) {
                        logger.error(e);
                    }
                }
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        logger.error(e);
                    }
                }
            }
        }
    }
  • 相关阅读:
    数据库之小问题
    网络基础
    react-fiber 解析
    【like-react】手写一个类似 react 的框架
    istat menus 序列号
    Git学习
    JavaScript设计模式与开发实践【第一部分】
    javascript 原生bind方法实现
    requirejs 学习
    mac 安装maven+eclipse
  • 原文地址:https://www.cnblogs.com/zwy0709/p/7920108.html
Copyright © 2011-2022 走看看