会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132602个问题
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 24633楼
Python 全系列/第三阶段:Python 网络与并发编程/网络通信 24635楼
WEB前端全系列/第十三阶段:微信小程序-安心食疗(旧)/安心食疗-购物车 24637楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 24638楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 24639楼
JAVA 全系列/第五阶段:JavaWeb开发/Web实战案例 24643楼

老师帮我看一下这个异常信息
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技术(旧) 24644楼
Python 全系列/第十阶段:Flask百战电商后台项目/Flask百战电商后台项目 24645楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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