zoukankan      html  css  js  c++  java
  • JDBC_Statement

    插入数据

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, NoSuchMethodException, InvocationTargetException, IOException {
            InputStream is = Jdbc_test.class.getClassLoader().getResourceAsStream("jdbc.propertise");
            Properties properties = new Properties();
            properties.load(is);
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");
            String url = properties.getProperty("url");
            String driver = properties.getProperty("driver");
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url,user,password);
            Statement statement = conn.createStatement();
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入账户");
            String username = sc.next();
            System.out.println("请输入密码");
            String userpassword = sc.next();
            String sql = "insert into emp values(default,'"+username+"','"+userpassword+"')";
            statement.execute(sql);
            statement.close();
            conn.close();
        }

    查询数据

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException, NoSuchMethodException, InvocationTargetException, IOException {
            //加载配置文件
            InputStream is = Jdbc_test.class.getClassLoader().getResourceAsStream("jdbc.propertise");
            Properties properties = new Properties();
            properties.load(is);
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");
            String url = properties.getProperty("url");
            String driver = properties.getProperty("driver");
            //连接数据库
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url,user,password);
            //查询结果
            Statement statement = conn.createStatement();
            String sql = "select * from emp;"; //SQL查询语句
            ResultSet rs = statement.executeQuery(sql); //执行查询语句
            //打印结果
            while(rs.next()){
                System.out.println(rs.getString("user")+"    "+
                        rs.getString("password"));
            }
            //关闭对象
            rs.close();
            statement.close();
            conn.close();
        }
  • 相关阅读:
    DRF 分页
    DRF 权限 频率
    DRF 版本 认证
    opencl(6)读写传输命令、内存映射命令
    opencl(5)缓存对象
    opencl(4)命令队列
    opencl(3)程序、内核
    opencl(2)平台、设备、上下文的获取与信息获取
    epoll
    unsigned 变量名:n
  • 原文地址:https://www.cnblogs.com/baisha/p/15463717.html
Copyright © 2011-2022 走看看