mysqlのデータベースの作成
【事前準備】
.NetbeansでMysqlを操作する前にXamppなどからMysqlの設定をして、MysqlをStartさせておく
【注意】
Eclipseで、MySQLを使うにはMySQL Connector/Jが必要に成る。
参考サイト→NetBeansでMySQLデータベースへ接続してみる
【NetbeansIDEからMySQLデータベースへの接続】
1.Netbeansを起動

・「サービス」タブをクリック
2.MySQLサーバーを登録

・「データベース」を右クリック

・「MySQLサーバーを登録」をクリック
3.MySQLサーバー・プロパティの設定

サーバー・ホスト名:localhost
サーバー・ポート番号:デフォルト設定
管理者のユーザー名:root
管理者のパスワード:xamppなどで設定したパスワード
4.MySQLサーバー接続

・データベースの下に、MySQLサーバーlocalhost:3306[root](切断)が表示される。

・MySQLサーバーlocalhost:3306[root](切断)を右クリックし、「接続」を選択する
5.MySQLデータベースの作成

・(切断)表示が消えて、MySQLサーバーlocalhost:3306[root]に成った事を確認
・MySQLサーバーlocalhost:3306[root]を右クリックして、データベースを作成を選択する
6.データベースの設定

・新規データベース名:testdbにする←自分の好み
・「OK」ボタンをクリック
7.データベース「testdb」の確認

データベース「testdb」が作成され、自動的に「testdb」に接続される。
8.テーブルの作成
ア)SQLエディタから作成してみる

・jdbc:mysql://localhost:3306/...[デフォルト・スキーマのroot]をクリックし、「コマンドの実行」を選択する
ア-1.SQLコマンドでテーブル書く

・見本コードはMySQLデータベースへの接続より
・「SQLの実行」のアイコンをクリック
ア-2.テーブル「counselor」の確認

・成功すると表の下に「counselor」が作られる
イ)ダイアログからテーブル作成

・「表」→「表の作成」をクリック

イ-1.「表を作成」画面の設定を行なう
・表名:subjectとする。
・「列の追加」ボタンをクリック
イ-2.「列の追加」画面の設定を行なう

「名前」:id
「タイプ」:SMALLINT
「制約」の必要な所にチェックを入れる
・「OK」ボタンをクリックする
「name」「description」「FK_counselorID」についても繰り返す
イ-3・完成

すべてのカラムを入れたら、「OK」ボタンをクリック
イ-4.「表」の下に「subject」が表示

9.データの入力と取得

テーブル「counselor」を右クリックして、「コマンドの実行」を選択する
10.SQLエディタからSQLコマンドを書く

コード書いたら「文の実行」アイコンをクリックする
11.表示

テーブル「counselor」を右クリックして「データの表示」を選択する

※コメント投稿者のブログIDはブログ作成者のみに通知されます