会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132382个问题
JAVA 全系列/第三阶段:数据库编程/JDBC技术 407楼
JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 408楼
JAVA 全系列/第三阶段:数据库编程/SQL 语言 410楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库的使用 411楼

老师帮我看一下这个异常信息
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技术(旧) 416楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 417楼
JAVA 全系列/第三阶段:数据库编程/SQL 语言 418楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库的使用 420楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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