标题:请问以下大佬们getResourceAsStream返回为null的问题
只看楼主
帝师
Rank: 2
来 自:湖南
等 级:论坛游民
帖 子:166
专家分:92
注 册:2018-10-11
结帖率:92.31%
 问题点数:0 回复次数:0 
请问以下大佬们getResourceAsStream返回为null的问题
我写的一个JDBCUtils工具类,在idea上能正常跑,但在eclipsegetResourceAsStream返回就为null了。路径没有问题我可以读出properties文件内容。路径前面也加过/也不行。所以求问哈论坛的大佬们这是为啥啊

public class JDBCUtils {
   
    private static DataSource DATA_SOURCE;

    static{
        Properties pro = new Properties();
        //ClassLoader classLoader = JDBCUtils.class.getClassLoader();
        InputStream in = JDBCUtils.class.getClassLoader().getResourceAsStream("src/main/resources/db.properties");

        try {
            pro.load(in);
            DATA_SOURCE = DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static Connection getConnection(){

        Connection conn = null;

        try {
            conn = DATA_SOURCE.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return conn;
    }

    public static void close(Connection conn, Statement st){


        if(st != null){
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if(conn != null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void  close(Connection conn, Statement st, ResultSet rs){

        if(rs != null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if(st != null){
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


        if(conn != null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
搜索更多相关主题的帖子: null close try catch conn 
2020-11-24 09:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-503988-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022847 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved