亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我得到的這個例外是什么,并幫助我?

我得到的這個例外是什么,并幫助我?

慕哥9229398 2022-08-03 10:37:51
package jdbc.examples;import java.io.FileInputStream;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import java.util.Properties;public class PropertiesDemo {    private static Connection conn;    private static Statement st;    private static ResultSet rs;    public static void main(String[] args) throws Exception{        Properties p = new Properties();        FileInputStream fis = new FileInputStream("db.properties");        p.load(fis);        String driver = (String)p.getProperty("driver");        String url = (String)p.getProperty("url");        String user = (String)p.getProperty("user");        String pwd = (String)p.getProperty("pwd");            Class.forName(driver);            conn = DriverManager.getConnection(url, user, pwd);            st = conn.createStatement();            rs = st.executeQuery("select ename, sal, deptno from emp");        while(rs.next()) {            System.out.println(rs.getString(1)+"  "+rs.getDouble(2)+"  "+rs.getInt(3));        }        rs.close();        st.close();        conn.close();    }}輸出:Exception in thread "main" java.io.FileNotFoundException: db.properties (The system cannot find the file specified)     at java.base/java.io.FileInputStream.open0(Native Method)   at java.base/java.io.FileInputStream.open(Unknown Source)   at java.base/java.io.FileInputStream.<init>(Unknown Source)     at j
查看完整描述

2 回答

?
汪汪一只貓

TA貢獻1898條經驗 獲得超8個贊

就像@Carlos和@PM77-1提到的那樣,答案是直截了當的“找不到文件”,用更簡單的術語來說,

FileInputStream fis = new FileInputStream(“db.properties”);

上面的行在 java 代碼的同一文件夾中搜索文件 db.properties,但未找到它。

解決方案:您可能需要移動屬性文件,或者您必須提及絕對/相對路徑

FileInputStream fis = new FileInputStream(“c:\myFile\db.properties”);


查看完整回答
反對 回復 2022-08-03
?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

您嘗試打開的文件不存在。下面的一行是導致問題的原因。最有可能的是,該文件位于另一個文件夾中或具有不同的名稱,因此我會先檢查一下。

FileInputStream fis = new FileInputStream("db.properties");


查看完整回答
反對 回復 2022-08-03
  • 2 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號