会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132387个问题
Python 全系列/下架-第十二阶段:Python_大型电商项目(5天后下架)/Django项目阶段-电商项目 8132楼

老师帮我看一下这个异常信息
package com.bjsxt.dao;

import com.bjsxt.common.jdbcUtils;
import com.bjsxt.pojo.Users;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserLoginDaoImpl implements UserLoginDao {
    @Override
    public boolean userLogin(String username, String password) {
        Connection conn = null;
        try{
            conn = jdbcUtils.getConnection();
            PreparedStatement ps = conn.prepareStatement("select * from bookusers where username=? and password=?");
            ps.setString(1, username);
            ps.setString(2, password);
            ResultSet resultSet = ps.executeQuery();
            if(resultSet.next()){
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            jdbcUtils.closeConnection(conn);
        }
        return false;
    }

    public static void main(String[] args) {
        UserLoginDaoImpl userLoginDaoImpl = new UserLoginDaoImpl();
        boolean b = userLoginDaoImpl.userLogin("憨憨崽", "hanhanzai");
        System.out.println(b);

    }
}




jdbc工具类:
package com.bjsxt.common;

import javax.annotation.Resource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class jdbcUtils {
    private static String driver;
    private static String url;
    private static String username;
    private static String password;

    static{
        try{
            ResourceBundle bundle = ResourceBundle.getBundle("db");
            driver = bundle.getString("jdbc.driver");
            url = bundle.getString("jdbc.url");
            username = bundle.getString("jdbc.username");
            password = bundle.getString("jdbc.password");
            Class.forName(driver);
        } catch(ClassNotFoundException e) {
            e.printStackTrace();

        }
    }

    //获取连接方法
    public static Connection getConnection(){
        Connection conn = null;
        try{
            conn = DriverManager.getConnection(url,username,password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void closeConnection(Connection conn) {
        try{
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}



异常信息:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.bjsxt.common.jdbcUtils
	at com.bjsxt.dao.UserLoginDaoImpl.userLogin(UserLoginDaoImpl.java:26)
	at com.bjsxt.dao.UserLoginDaoImpl.main(UserLoginDaoImpl.java:33)


JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 8135楼

package com.bjsxt.shiro02;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

public class TestB {
    public static void main(String[] args) {
        //[1]解析shiro.ini 文件
        IniSecurityManagerFactory factory =new IniSecurityManagerFactory("classpath:shiro04-jdbc.ini ");
        //[2]通过SecurityManager 工厂获得SecurityManager 实例
        SecurityManager securityManager = factory.getInstance();
        //[3]用SecurityUtils把SecurityManager 对象设置到运行
        SecurityUtils.setSecurityManager(securityManager);
        //[4]通过SecurityUtils 获得主体 subject
        Subject subject = SecurityUtils.getSubject();
        //[5]书写自己输入的账号和密码---相当于用户自己输入的账号和密码
//我们拿着自己书写用户名密码去和shiro.ini 文件中的账号密码比较
        UsernamePasswordToken token = new UsernamePasswordToken("root","root");
        try {
            //[6]进行身份的验证
            subject.login(token);
            //[7]通过方法判断是否登录成功
            if (subject.isAuthenticated()) {
                System.out.println("登录成功");
            }
        }catch (IncorrectCredentialsException e){
            System.out.println("凭证(密码)不正确");
        }catch (UnknownAccountException e1){
            System.out.println("用户名不正确");
        }catch (ExpiredCredentialsException e){
            System.out.println("凭证过期");
        }catch (ExcessiveAttemptsException e){
            System.out.println("尝试次数过多");
            e.printStackTrace();
        }catch (ConcurrentAccessException e){
            System.out.println("竞争次数过多");
        }
    }
}

自定义Realm文件

package com.bjsxt.shiro02;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 自定义Realm
 */

/**
 * 授权
 */
public class UserRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    /**
     * 认证
     * @param authenticationToken
     * @return
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shiro","root","zjx666888");
            PreparedStatement preparedStatement = conn.prepareStatement("select uname,pwd from user");
            ResultSet rs = preparedStatement.executeQuery();
            while (rs.next()){
                //把查到的数据集合给这个对象
                SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(rs.getString("uname"),rs.getString("pwd"),"real");
                return info;
            }

        }catch (Exception e){
        }
        return null;
    }


}

ini配置文件

image.png


数据库内容

image.png

image.png


老师为什么我输入sxt和123就可以登录成功,输入其他的就是密码错误??????????????


image.png

JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 8136楼
Python 全系列/第一阶段:Python入门/序列 8137楼

During handling of the above exception, another exception occurred: 

Traceback (most recent call last):
  File "d:\program files\python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher
    yield
  File "d:\program files\python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "d:\program files\python39\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "d:\program files\python39\lib\http\client.py", line 458, in 
read
    n = self.readinto(b)
  File "d:\program files\python39\lib\http\client.py", line 502, in 
readinto
    n = self.fp.readinto(b)
  File "d:\program files\python39\lib\socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "d:\program files\python39\lib\ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "d:\program files\python39\lib\ssl.py", line 1099, in read   
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred: 

Traceback (most recent call last):
  File "d:\program files\python39\lib\site-packages\pip\_internal\cli\base_command.py", line 189, in _main
    status = self.run(options, args)
  File "d:\program files\python39\lib\site-packages\pip\_internal\cli\req_command.py", line 178, in wrapper
    return func(self, options, args)
  File "d:\program files\python39\lib\site-packages\pip\_internal\commands\install.py", line 316, in run
    requirement_set = resolver.resolve(
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 121, in resolve
    self._result = resolver.resolve(
  File "d:\program files\python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 453, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds) 
  File "d:\program files\python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 318, in resolve
    name, crit = self._merge_into_criterion(r, parent=None)
  File "d:\program files\python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 173, in _merge_into_criterion
    crit = Criterion.from_requirement(self._p, requirement, parent) 
  File "d:\program files\python39\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 82, in from_requirement
    if not cands:
  File "d:\program files\python39\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 124, in __bool__
    return bool(self._sequence)
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in __bool__     
    return any(self)
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 38, in _iter_built   
    candidate = func()
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 167, in _make_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 300, in __init__
    super().__init__(
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 144, in __init__
    self.dist = self._prepare()
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 226, in _prepare
    dist = self._prepare_distribution()
  File "d:\program files\python39\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 311, in _prepare_distribution
    return self._factory.preparer.prepare_linked_requirement(       
  File "d:\program files\python39\lib\site-packages\pip\_internal\operations\prepare.py", line 457, in prepare_linked_requirement       
    return self._prepare_linked_requirement(req, parallel_builds)   
  File "d:\program files\python39\lib\site-packages\pip\_internal\operations\prepare.py", line 480, in _prepare_linked_requirement      
    local_file = unpack_url(
  File "d:\program files\python39\lib\site-packages\pip\_internal\operations\prepare.py", line 230, in unpack_url
    file = get_http_url(
  File "d:\program files\python39\lib\site-packages\pip\_internal\operations\prepare.py", line 108, in get_http_url
    from_path, content_type = download(link, temp_dir.path)
  File "d:\program files\python39\lib\site-packages\pip\_internal\network\download.py", line 163, in __call__
    for chunk in chunks:
  File "d:\program files\python39\lib\site-packages\pip\_internal\cli\progress_bars.py", line 159, in iter
    for x in it:
  File "d:\program files\python39\lib\site-packages\pip\_internal\network\utils.py", line 64, in response_chunks
    for chunk in response.raw.stream(
  File "d:\program files\python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 576, in stream
    data = self.read(amt=amt, decode_content=decode_content)        
  File "d:\program files\python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 541, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "d:\program files\python39\lib\contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "d:\program files\python39\lib\site-packages\pip\_vendor\urllib3\response.py", line 443, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.")     
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

老师,我在安装 python-pptx 这个包的时候,报了上面的错误,请问如何解决呢?

Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/自动化操作办公软件、邮件、定时任务等 8138楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 8140楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/HTML5基础元素 8142楼
Python 全系列/第一阶段:Python入门/编程基本概念 8143楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 8144楼
JAVA 全系列/第十三阶段:分布式文件存储与数据缓存/FastDFS 8145楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637