关于IntelliJ IDEA创建项目无法读取配置文件
来源:互联网 发布:java style 编辑:程序博客网 时间:2024/06/17 15:29
一开始是用JDBC读取外部的数据库配置文件,文件如下:
package hanxiu.util;import java.io.InputStream;import java.sql.*;import java.util.Properties;/** * JDBC工具类: * 1) 获取Connection * 2) 释放资源 */public class JDBCUtil { /** * 获取Connection * @return 所获得到的JDBC的Connection */ public static Connection getConnection() throws Exception { /** * 不建议大家把配置硬编码到代码中 * * 最佳实践:配置性的建议写到配置文件中// String url = "jdbc:mysql:///springdata";// String user = "root";// String password = "123";// String driverClass = "com.mysql.jdbc.Driver"; InputStream inputStream = JDBCUtil.class.getClassLoader().getResourceAsStream("db.properties"); Properties properties = new Properties(); System.out.print(inputStream); properties.load(inputStream); String url = properties.getProperty("jdbc.url"); String user = properties.getProperty("jdbc.user"); String password = properties.getProperty("jdbc.password"); String driverClass = properties.getProperty("jdbc.driverClass"); Class.forName(driverClass); Connection connection = DriverManager.getConnection(url, user, password); return connection; } /** * 释放DB相关的资源 * @param resultSet * @param statement * @param connection */ public static void release(ResultSet resultSet, Statement statement, Connection connection){ if(resultSet != null) { try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } } if(statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } } if(connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } }}
一直无法读取到db.properties,报的错误如下
后面通过找资料观查发现才知道文件夹的类型没设置,通过这样设置可以解决问题
4 0
- 关于IntelliJ IDEA创建项目无法读取配置文件
- 解决IntelliJ IDEA无法读取配置文件的问题
- IntelliJ IDEA 创建项目
- Intellij Idea 创建项目
- IntelliJ IDEA 之 HelloWorld 项目创建及相关配置文件介绍
- IntelliJ IDEA 之 HelloWorld 项目创建及相关配置文件介绍
- IntelliJ IDEA修改读取配置文件的路径
- IntelliJ IDEA修改读取配置文件的路径
- Intellij idea+maven创建项目
- Intellij Idea 创建JavaWeb项目
- Intellij Idea 创建JavaWeb项目
- IntelliJ IDEA创建 SBT项目
- IntelliJ IDEA 创建Java项目
- Intellij IDEA创建maven项目
- Intellij Idea 创建JavaWeb项目
- IntelliJ IDEA创建项目技巧
- IntelliJ IDEA 创建Web项目
- IntelliJ IDEA 创建Web项目
- 消息队列
- Linux 命令行里的“瑞士军刀”
- 使用SimpleAdapter创建ListView
- php-pfm.conf
- 结合Wireshark理解TCP连接建立所需的三次握手
- 关于IntelliJ IDEA创建项目无法读取配置文件
- centos7.2下安装php7.1缺少依赖包汇总(初稿)
- Watson Explorer 入门(13):配置中断规则
- 基于windows系统上搭建的android应用集成React native的成功案列
- java——File类
- string 与char* char[]之间的转换
- mongodb的基本操作命令
- 三步创建免费微信砍价活动攻略,开发者福音
- 错误:error C1853:"Debug\...pch"预编译头文件来自编译器版本,或者预编译头C++而在C中使用它