zoukankan      html  css  js  c++  java
  • jdbc

    JDBC模板

    public class mysql {
        public static void main(String[] args) throws ClassNotFoundException, SQLException {
            //加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //用户信息 和url
            String url="jdbc:mysql://localhost:3306/school?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=true";
            String name="root";
            String pwd="123456";
            //连接成功,得到数据库对象
            Connection connection = DriverManager.getConnection(url, name, pwd);
            //执行sql的对象statement
            Statement statement = connection.createStatement();
            //执行sql的对象去执行sql语句
            String sql="select * from users";
            ResultSet resultSet = statement.executeQuery(sql);
            while(resultSet.next()){
                System.out.println("id"+resultSet.getObject("id"));
                System.out.println("NAME"+resultSet.getObject("NAME"));
                System.out.println("PASSWORD"+resultSet.getObject("PASSWORD"));
                System.out.println("email"+resultSet.getObject("email"));
                System.out.println("birthday"+resultSet.getObject("birthday"));
            }
            //释放连接
            resultSet.close();
            statement.close();
            connection.close();
        }
    }
    
    
  • 相关阅读:
    html优化
    HTML练习(网页计算器)
    hdu--4574 Bombs(dfs)
    Robots at Warehouse(搜索+vector的使用)
    poj 2111 Millenium Leapcow(记忆化搜索)
    Codeforces Round #408 (Div. 2) C. Bank Hacking(暴力啊!暴力)
    Gym
    Gym
    浙江省赛--D
    浙江省赛--C
  • 原文地址:https://www.cnblogs.com/xiaxiaopi/p/14376802.html
Copyright © 2011-2022 走看看