使用Properties配置jdbc

2021-09-25 04:49:07 字數 742 閱讀 4413

properties類的load方法需要讀取乙個***.properties配置檔案

我在專案下建立了乙個config資料夾,在資料夾中新建jdbc.properties配置檔案

在jdbc.properties中寫入我的配置資訊

jdbc.driver = com.mysql.jdbc.driver

jdbc.url = jdbc:mysql://localhost:3307/stumanage?useunicode=true&characterencoding=utf8

jdbc.user = root

jdbc.password = 123456

新建乙個propertiesutil類

public class propertiesutil  catch (filenotfoundexception e)  catch (ioexception e) 

} public static string getvaluebykey(string key)

return null;

}}

在需要使用配置檔案的位置:

propertiesutil.getvaluebykey("jdbc.driver")

Properties配置檔案

在應用jdbc連線mysql陣列庫過程中,有以下幾步準備工作 一 匯入mysql驅動包 1 選擇路徑 二 配置檔案位置 命名 格式 不同於myeclipse,它比較智慧型 1 在src目錄下 2 命名一般是 dbconfig.properties 3 鍵值對形式儲存,值不需要 修飾 三 這基本就是初...

properties配置檔案

開發中獲得連線的四個引數 驅動,url,使用者名稱,密碼 通常都存在配置檔案中,方便後期維護,程式如果需要更換資料庫,只需要修改配置檔案即可。通常情況下,我們習慣使用properties檔案,此檔案要求 檔案位置 任意,建議src下 非web應用 classpath web應用 檔名 任意,擴充套件...

mybatis配置 properties標籤

123 456 name driver value com.mysql.jdbc.driver name url value jdbc mysql localhost 3306 mybatis name username value root name password value root pro...