<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # properties配置文件 開發中獲得連接的4個參數(驅動、URL、用戶名、密碼)通常都存在配置文件中,方便后期維護,程序如果需要更換數據庫,只需要修改配置文件即可 通常情況下,我們習慣使用properties文件,此文件我們將做如下要求: 1. 文件位置:任意,建議src下 2. 文件名稱:任意,擴展名為properties 3. 文件內容:一行一組數據,格式是“key=value”. a) key命名自定義,如果是多個單詞,習慣使用點分隔。例如:jdbc.driver b) value值不支持中文,如果需要使用非英文字符,將進行unicode轉換。 * 創建配置文件 在項目跟目錄下,創建文件,輸入“db.properties”文件名。 文件中的內容 ~~~ driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/mydb user=root password=root ~~~ * 加載配置文件:Properties對象 對應properties文件處理,開發中也使用Properties對象進行。我們將采用加載properties文件獲得流,然后使用Properties對象進行處理。 JDBCUtils.java中編寫代碼 ~~~ public class JDBCUtils { private static String driver; private static String url; private static String user; private static String password; // 靜態代碼塊 static { try { // 1 使用Properties處理流 // 使用load()方法加載指定的流 Properties props = new Properties(); Reader is = new FileReader("db.properties"); props.load(is); // 2 使用getProperty(key),通過key獲得需要的值, driver = props.getProperty("driver"); url = props.getProperty("url"); user = props.getProperty("user"); password = props.getProperty("password"); } catch (Exception e) { throw new RuntimeException(e); } } /** * 獲得連接 */ public static Connection getConnection() { try { // 1 注冊驅動 Class.forName(driver); // 2 獲得連接 Connection conn = DriverManager.getConnection(url, user, password); return conn; } catch (Exception e) { throw new RuntimeException(e); } } } ~~~ ## ResourceBundle 工具 ~~~ //jdk提供的工具類加載properties文件,名字db.properties的后綴可以省略 ResourceBundle bundle = ResourceBundle.getBundle("db"); //通過key獲得需要的值 String driver = bundle.getString("driver"); System.out.println(driver); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看