【JAVA】JDBCでDBに接続する準備



# JDBCを利用してJavaからデータベースにアクセスする方法

JDBCをインストールしJavaのプロジェクトに接続するための準備を行います。

## JDBCドライバとは
Javaプログラムに対して定義した機能を提供し、DBへ接続して処理を行う部分です。
ほとんどのデータベース各社が提供しています。

## PostgreSQLに接続する準備
### 事前準備
まず、前提として以下の2点を済ませておくこと。

- データベース、テーブル、データの投入SQLの実行確認
- [PostgreSQLのドライバ](https://jdbc.postgresql.org/download.html)のダウンロード
- プロジェクトを作成

JDBCドライバのjarファイルをプロジェクトのクラスパスに追加します。
Eclipse上から以下の操作を行います。

3. プロジェクト内のフォルダに「lib」フォルダを選ぶ
4. postgresqlのjarファイル をコピー
3. コピーしたjarファイルを右クリック「ビルド・パス」→「ビルド・パスに追加」

ビルド・パスの追加に成功すると、「参照ライ
展開すると、追加したjarファイルが表示される。

<!-- 参考にした資料のリンクを貼る -->
<!-- ## 参考文献・記事 -->



<!-- 以下ショートリンク↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ -->
[Progate]:https://prog-8.com/
[ドットインストール]:https://dotinstall.com/
<!-- A -->
[abstract修飾子]:https://qiita.com/takahirocook/items/9fa0e1cbb8a4dd4e1ff4
[abstract]:https://qiita.com/takahirocook/items/9fa0e1cbb8a4dd4e1ff4
<!-- B -->
<!-- C -->
[Calendar]:https://qiita.com/takahirocook/items/204dd7331db777eb6f3b
<!-- D -->
[Date]:https://qiita.com/takahirocook/items/a760e20ef2d9aa5c08fc
<!-- E -->
<!-- F -->
[final]:https://qiita.com/takahirocook/items/5e0916d9bf28bcf68d0c
[final修飾子]:https://qiita.com/takahirocook/items/5e0916d9bf28bcf68d0c
<!-- G -->
[getter・setter]:https://qiita.com/takahirocook/items/27828bc8477735612021
[getter]:https://qiita.com/takahirocook/items/27828bc8477735612021
[GET]:https://qiita.com/takahirocook/items/8080a478439f6043b2c1
[GETメソッド]:https://qiita.com/takahirocook/items/8080a478439f6043b2c1
[getParameter()]:https://qiita.com/takahirocook/items/8080a478439f6043b2c1
[getParameter]:https://qiita.com/takahirocook/items/8080a478439f6043b2c1
[getParameterメソッド]:(https://qiita.com/takahirocook/items/8080a478439f6043b2c1)
[getParameterValues]:https://qiita.com/takahirocook/items/7a071493ae73cc4749e1
[getParameterValuesメソッド]:https://qiita.com/takahirocook/items/7a071493ae73cc4749e1
<!-- H -->
<!-- I -->
[import]:https://qiita.com/takahirocook/items/59a8a09cab6a98d3bca2
<!-- J -->
[JDBC]:https://qiita.com/takahirocook/items/064b591cffa4221144ed
<!-- K -->
<!-- L -->
[List]:https://qiita.com/takahirocook/items/4d622fc6f271569783b5
[length]:https://qiita.com/takahirocook/items/16a123fb73b30869053b
[list]:https://qiita.com/takahirocook/items/4d622fc6f271569783b5
<!-- M -->
[Map]:https://qiita.com/takahirocook/items/49f46151ecb5e332db32
[map]:https://qiita.com/takahirocook/items/49f46151ecb5e332db32
[mainメソッド]:https://qiita.com/takahirocook/items/f4635915337303de338c
<!-- N -->
[new演算子]:https://qiita.com/takahirocook/items/00f9f97592bf50831d39
[new]:https://qiita.com/takahirocook/items/00f9f97592bf50831d39
<!-- O -->
<!-- P -->
[printf()メソッド]:https://qiita.com/takahirocook/items/06d525be63eccd99ed49
[printf()関数]:https://qiita.com/takahirocook/items/06d525be63eccd99ed49
[POST]:https://qiita.com/takahirocook/items/7a071493ae73cc4749e1
[POSTメソッド]:https://qiita.com/takahirocook/items/7a071493ae73cc4749e1
<!-- Q -->
<!-- R -->
<!-- S -->
[static修飾子]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[static]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[setter]:https://qiita.com/takahirocook/items/27828bc8477735612021
[SimpleDateFormat]:https://qiita.com/takahirocook/items/aa857c8f2153193095e4
[set]:https://qiita.com/takahirocook/items/d498329cd26e1500f476
[Set]:https://qiita.com/takahirocook/items/d498329cd26e1500f476
[super]:https://qiita.com/takahirocook/items/75a07131e7e791c8442c
<!-- T -->
[this]:https://qiita.com/takahirocook/items/d251ec4693c68f6b9538
[Time]:https://qiita.com/takahirocook/items/9caef0bb2409caedba55
[this]:https://qiita.com/takahirocook/items/d251ec4693c68f6b9538
[web.xml]:https://qiita.com/takahirocook/items/d41a92bd36807d456f82
<!-- U -->
<!-- V -->
<!-- W -->
<!-- X -->
<!-- Y -->
<!-- Z -->
<!-- あ行 -->
[オブジェクト指向]:https://qiita.com/takahirocook/items/041ba7a096b71ab8ffd4
[継承]:https://qiita.com/takahirocook/items/6c84ea66a6e2ad536a37
[オーバーライド]:https://qiita.com/takahirocook/items/09dd8e5f56d6617ce45a
[オーバーロード]:https://qiita.com/takahirocook/items/b937c3c07126fe7e02a4
[インスタンス]:https://qiita.com/takahirocook/items/ec01cdcbb440cf0d1cc4
[インスタンス化]:https://qiita.com/takahirocook/items/ec01cdcbb440cf0d1cc4
[アクセス修飾子]:https://qiita.com/takahirocook/items/e51b0b9d37d95ad587fe
[インスタンス化]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[インスタンス変数]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[インターフェイス]:https://qiita.com/takahirocook/items/ca84be8dfef664b19194
[インターフェース]:https://qiita.com/takahirocook/items/ca84be8dfef664b19194
[インポート]:https://qiita.com/takahirocook/items/59a8a09cab6a98d3bca2
[インデックス]:https://qiita.com/takahirocook/items/16a123fb73b30869053b
<!-- か行 -->
[拡張for文]:https://qiita.com/takahirocook/items/470b2858de1a4f99b334
[クラスメソッド]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[クラスフィールド]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[クラス変数]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[カプセル化]:https://qiita.com/takahirocook/items/e469a7c0539a0012868e
[クラス]:https://qiita.com/takahirocook/items/50cbbdca8e21539170e9
[コンストラクタ]:https://qiita.com/takahirocook/items/fa1822f2f22c3786593e
<!-- さ行 -->
[サーブレット]:https://qiita.com/takahirocook/items/1ee780d68fd859e43daf
[書式指定子]:https://qiita.com/takahirocook/items/06d525be63eccd99ed49
[静的メソッド]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[静的変数]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[静的メソッド]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
[スーパークラス]:https://qiita.com/takahirocook/items/75a07131e7e791c8442c
<!-- た行 -->
[定数]:https://qiita.com/takahirocook/items/5e0916d9bf28bcf68d0c
[抽象クラス]:https://qiita.com/takahirocook/items/9fa0e1cbb8a4dd4e1ff4
[抽象メソッド]:https://qiita.com/takahirocook/items/9fa0e1cbb8a4dd4e1ff4
[動的メソッド]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
<!-- な行 -->
[日時の文字列操作]:https://qiita.com/takahirocook/items/aa857c8f2153193095e4
<!-- は行 -->
[パッケージ]:https://qiita.com/takahirocook/items/39b58d17abcb159ef5c1
[引数]:https://qiita.com/takahirocook/items/5e5b0ba79e869f4a592e
[配列]:https://qiita.com/takahirocook/items/16a123fb73b30869053b
[配列操作]:https://qiita.com/takahirocook/items/16a123fb73b30869053b
[日付操作]:https://qiita.com/takahirocook/items/9caef0bb2409caedba55
[フィールド]:https://qiita.com/takahirocook/items/28df75a133049a74ece1
[フィールド変数]:https://qiita.com/takahirocook/items/28df75a133049a74ece1
[インスタンスフィールド]:https://qiita.com/takahirocook/items/cf527f85d17a5af86735
<!-- ま行 -->
[戻り値]:https://qiita.com/takahirocook/items/3b6fa670a1d6dd4a9386
[メソッド]:https://qiita.com/takahirocook/items/5bfe43576d87a2a4006c
[メソッドの呼び出し]:https://qiita.com/takahirocook/items/f4635915337303de338c
<!-- や行 -->
<!-- ら行 -->
<!-- わ行 -->