【无标题】

【无标题】,第1张

-- 创建用户
CREATE USER 'add'@'localhost' IDENTIFIED BY '1234';
-- 授予权限 all 所有 *.* 
GRANT select  ON db1.jdbc_user TO 'add'@'localhost';

-- 查询用户 
select * from mysql.`user`;

-- 查看权限
SHOW GRANTS FOR 'add'@'localhost';

 

-- 删除用户权限
revoke select on db1.jdbc_user from 'add'@'localhost';

 

 

-- 删除用户
drop user 'add'@'localhost';

数据备份与还原 

 

 选择转储sql文件 选择结构与数据

删除数据库db1 进行数据库还原

 

选择sql 文件 运行 

 

 使用JDBC,连接数据库,并查询一个表格中的数据
package com.qiku.HomeWork;

import java.sql.*;

public class H1 {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            // 1. 注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            // 2.获取与mysql的链接
            connection = DriverManager.getConnection(
                            );
            // 3.通过Statement 生成的对象 执行 mysql 语句
            statement = connection.createStatement();
           resultSet = statement.executeQuery("select * from products");
            while(resultSet.next()){
                String pid = resultSet.getString("pid");
                String pName = resultSet.getString("pname");
                String price = resultSet.getString("price");
                String flag = resultSet.getString("flag");
                String category_id = resultSet.getString("category_id");
                System.out.println("pid = "+pid+",pName = "+pName+",price = "+price+",flag = "+ flag +",category_id = "+ category_id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                assert resultSet != null;
                resultSet.close();
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/757241.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-30
下一篇2022-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存