質問編集履歴

6

流れの記載

2018/03/18 12:04

投稿

stringA
stringA

スコア19

test CHANGED
File without changes
test CHANGED
@@ -9,6 +9,8 @@
9
9
  今回私がやりたいことは、localhost上のテーブルにあるカラム「社員番号」と「社員名」のフィールドデータを、下記画像のプルダウンに表示させたいと思っています。
10
10
 
11
11
 
12
+
13
+ 以下、「UIクラス2」
12
14
 
13
15
  ![イメージ説明](4814eb71edf195e9aaf1bdf06b2e8f6a.png)
14
16
 
@@ -31,6 +33,16 @@
31
33
  現在のコードを転載させていただきます。
32
34
 
33
35
  ```Java
36
+
37
+
38
+
39
+ /**
40
+
41
+ *UIクラス
42
+
43
+ */
44
+
45
+
34
46
 
35
47
  package ui;
36
48
 
@@ -156,6 +168,24 @@
156
168
 
157
169
 
158
170
 
171
+
172
+
173
+ *追記
174
+
175
+ 【流れ】
176
+
177
+ ① UIクラス1で「検索」を押すとUIクラス2の画面へ遷移
178
+
179
+ ② UIクラス2の画面(上記キャプチャ画像)のプルダウンで情報が取得されている状態を作る。
180
+
181
+ ③ 終了
182
+
183
+
184
+
185
+
186
+
187
+
188
+
159
189
  もし、お分りの方がいらっしゃいましたら、お力添えを頂けますと幸いです。
160
190
 
161
191
  よろしくお願い致します。

5

コードの変更

2018/03/18 12:04

投稿

stringA
stringA

スコア19

test CHANGED
File without changes
test CHANGED
@@ -32,195 +32,123 @@
32
32
 
33
33
  ```Java
34
34
 
35
- package jp.co.witc.groupexercise.dao.i_dao;
35
+ package ui;
36
36
 
37
37
 
38
38
 
39
- import java.sql.Connection;
39
+ import java.awt.EventQueue;
40
40
 
41
- import java.sql.DriverManager;
42
-
43
- import java.sql.PreparedStatement;
44
-
45
- import java.sql.ResultSet;
46
-
47
- import java.sql.SQLException;
48
-
49
- import java.util.ArrayList;
50
-
51
- import java.util.Collections;
52
-
53
- import java.util.List;
41
+ import java.awt.Font;
54
42
 
55
43
 
56
44
 
57
- import dto.DTO_CheckStock;
45
+ import javax.swing.JComboBox;
58
46
 
59
- import jp.co.witc.groupexercise.common.I_IO_OutputForm;
47
+ import javax.swing.JFrame;
48
+
49
+ import javax.swing.JLabel;
60
50
 
61
51
 
62
52
 
63
- public class DAO_CheckStock implements I_IO_OutputForm{
53
+ public class TEST_UI {
64
54
 
65
-
66
55
 
67
- public static void find(DTO_1 _Dto) {
68
56
 
69
- ResultSet rst = null;
57
+ private JFrame frame;
70
58
 
71
- DAO_Entity inr_entity = null;
72
59
 
73
- Connection con = null;
74
60
 
61
+ /**
62
+
63
+ * Launch the application.
64
+
65
+ */
66
+
67
+ public static void main(String[] args) {
68
+
69
+ EventQueue.invokeLater(new Runnable() {
70
+
71
+ public void run() {
72
+
73
+ try {
74
+
75
+ TEST_UI window = new TEST_UI();
76
+
77
+ window.frame.setVisible(true);
78
+
79
+ } catch (Exception e) {
80
+
81
+ e.printStackTrace();
82
+
83
+ }
84
+
85
+ }
86
+
87
+ });
88
+
89
+ }
90
+
91
+
92
+
93
+ /**
94
+
95
+ * Create the application.
96
+
97
+ */
98
+
99
+ public TEST_UI() {
100
+
101
+ initialize();
102
+
103
+ }
104
+
105
+
106
+
107
+ /**
108
+
109
+ * Initialize the contents of the frame.
110
+
111
+ */
112
+
113
+ private void initialize() {
114
+
115
+ frame = new JFrame();
116
+
117
+ frame.setBounds(100, 100, 483, 316);
118
+
119
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
120
+
75
- PreparedStatement pstmt = null;
121
+ frame.getContentPane().setLayout(null);
76
122
 
77
123
 
78
124
 
125
+ /**
126
+
79
- List<DAO_Entity> inr_listDAO_EntitySamlpe = new ArrayList<DAO_Entity>();
127
+ * 以下よりプルダウン表示コード
128
+
129
+ */
80
130
 
81
131
 
82
132
 
83
- try{
133
+ JComboBox comboBox = new JComboBox();
84
134
 
85
-
135
+ comboBox.setBounds(215, 75, 149, 49);
86
136
 
87
- Class.forName(CONST_DB_DRIVER_NAME);
137
+ frame.getContentPane().add(comboBox);
88
138
 
89
-
139
+
90
140
 
91
-
141
+ JLabel lblNewLabel = new JLabel("社員番号 社員名:");
92
142
 
93
-
143
+ lblNewLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 20));
94
144
 
95
- con = DriverManager.getConnection(CONST_DB_AUTH_INFORMATION);
145
+ lblNewLabel.setBounds(35, 90, 200, 21);
96
146
 
97
-
98
-
99
-
100
-
101
-
102
-
103
- StringBuilder sbrSql = new StringBuilder();
104
-
105
- sbrSql.append("SELECT");
106
-
107
- sbrSql.append(" P_ID, P_NAME");
108
-
109
- sbrSql.append(" FROM");
110
-
111
- sbrSql.append(" project");
112
-
113
-
114
-
115
- sbrSql.append(" WHERE");
116
-
117
- sbrSql.append(" P_ID = ? AND");
118
-
119
- sbrSql.append(" P_NAME = ? ");
120
-
121
-
122
-
123
-
124
-
125
- pstmt = con.prepareStatement(sbrSql.toString());
126
-
127
-
128
-
129
-
130
-
131
- pstmt.setString(1, _paramDto.getShohin_id_mei());
132
-
133
-
134
-
135
- pstmt.setString(2, _paramDto.getZaikosu());
136
-
137
- System.out.println(pstmt);
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
- rst = pstmt.executeQuery();
146
-
147
-
148
-
149
- System.out.println("----------------------------------------------------------------------------------"); // "\t|"で>を出す
150
-
151
- System.out.println("P_ID" + "\t|" + "P_NAME");
152
-
153
- System.out.println("----------------------------------------------------------------------------------");
154
-
155
-
156
-
157
-
158
-
159
- while(rst.next()){
160
-
161
- inr_entity = new DAO_Entity(rst.getString("P_ID"), rst.getString("P_NAME"));
162
-
163
- System.out.println(inr_entity.getCol_Id() + "\t|" + inr_entity.getCol_Name());
164
-
165
-
166
-
167
- inr_listDAO_EntitySamlpe.add(inr_entity);
147
+ frame.getContentPane().add(lblNewLabel);
168
-
169
- }
170
-
171
-
172
-
173
- List<DAO_Entity> newList = Collections.unmodifiableList(inr_listDAO_EntitySamlpe);
174
-
175
-
176
-
177
- }catch (ClassNotFoundException e){
178
-
179
- e.printStackTrace();
180
-
181
- }catch (SQLException e){
182
-
183
- e.printStackTrace();
184
-
185
- }finally {
186
-
187
- try{
188
-
189
- if (rst != null){
190
-
191
- rst.close();
192
-
193
- }//
194
-
195
- if (pstmt != null){
196
-
197
- pstmt.close();
198
-
199
- }//
200
-
201
- if(con != null){
202
-
203
- con.close();
204
-
205
- }
206
-
207
- }catch (SQLException e){
208
-
209
- e.printStackTrace();
210
-
211
- }
212
-
213
- }
214
148
 
215
149
  }
216
150
 
217
151
  }
218
-
219
-
220
-
221
-
222
-
223
-
224
152
 
225
153
 
226
154
 

4

コードの追加

2018/03/18 11:44

投稿

stringA
stringA

スコア19

test CHANGED
File without changes
test CHANGED
@@ -28,6 +28,206 @@
28
28
 
29
29
 
30
30
 
31
+ 現在のコードを転載させていただきます。
32
+
33
+ ```Java
34
+
35
+ package jp.co.witc.groupexercise.dao.i_dao;
36
+
37
+
38
+
39
+ import java.sql.Connection;
40
+
41
+ import java.sql.DriverManager;
42
+
43
+ import java.sql.PreparedStatement;
44
+
45
+ import java.sql.ResultSet;
46
+
47
+ import java.sql.SQLException;
48
+
49
+ import java.util.ArrayList;
50
+
51
+ import java.util.Collections;
52
+
53
+ import java.util.List;
54
+
55
+
56
+
57
+ import dto.DTO_CheckStock;
58
+
59
+ import jp.co.witc.groupexercise.common.I_IO_OutputForm;
60
+
61
+
62
+
63
+ public class DAO_CheckStock implements I_IO_OutputForm{
64
+
65
+
66
+
67
+ public static void find(DTO_1 _Dto) {
68
+
69
+ ResultSet rst = null;
70
+
71
+ DAO_Entity inr_entity = null;
72
+
73
+ Connection con = null;
74
+
75
+ PreparedStatement pstmt = null;
76
+
77
+
78
+
79
+ List<DAO_Entity> inr_listDAO_EntitySamlpe = new ArrayList<DAO_Entity>();
80
+
81
+
82
+
83
+ try{
84
+
85
+
86
+
87
+ Class.forName(CONST_DB_DRIVER_NAME);
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ con = DriverManager.getConnection(CONST_DB_AUTH_INFORMATION);
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ StringBuilder sbrSql = new StringBuilder();
104
+
105
+ sbrSql.append("SELECT");
106
+
107
+ sbrSql.append(" P_ID, P_NAME");
108
+
109
+ sbrSql.append(" FROM");
110
+
111
+ sbrSql.append(" project");
112
+
113
+
114
+
115
+ sbrSql.append(" WHERE");
116
+
117
+ sbrSql.append(" P_ID = ? AND");
118
+
119
+ sbrSql.append(" P_NAME = ? ");
120
+
121
+
122
+
123
+
124
+
125
+ pstmt = con.prepareStatement(sbrSql.toString());
126
+
127
+
128
+
129
+
130
+
131
+ pstmt.setString(1, _paramDto.getShohin_id_mei());
132
+
133
+
134
+
135
+ pstmt.setString(2, _paramDto.getZaikosu());
136
+
137
+ System.out.println(pstmt);
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ rst = pstmt.executeQuery();
146
+
147
+
148
+
149
+ System.out.println("----------------------------------------------------------------------------------"); // "\t|"で>を出す
150
+
151
+ System.out.println("P_ID" + "\t|" + "P_NAME");
152
+
153
+ System.out.println("----------------------------------------------------------------------------------");
154
+
155
+
156
+
157
+
158
+
159
+ while(rst.next()){
160
+
161
+ inr_entity = new DAO_Entity(rst.getString("P_ID"), rst.getString("P_NAME"));
162
+
163
+ System.out.println(inr_entity.getCol_Id() + "\t|" + inr_entity.getCol_Name());
164
+
165
+
166
+
167
+ inr_listDAO_EntitySamlpe.add(inr_entity);
168
+
169
+ }
170
+
171
+
172
+
173
+ List<DAO_Entity> newList = Collections.unmodifiableList(inr_listDAO_EntitySamlpe);
174
+
175
+
176
+
177
+ }catch (ClassNotFoundException e){
178
+
179
+ e.printStackTrace();
180
+
181
+ }catch (SQLException e){
182
+
183
+ e.printStackTrace();
184
+
185
+ }finally {
186
+
187
+ try{
188
+
189
+ if (rst != null){
190
+
191
+ rst.close();
192
+
193
+ }//
194
+
195
+ if (pstmt != null){
196
+
197
+ pstmt.close();
198
+
199
+ }//
200
+
201
+ if(con != null){
202
+
203
+ con.close();
204
+
205
+ }
206
+
207
+ }catch (SQLException e){
208
+
209
+ e.printStackTrace();
210
+
211
+ }
212
+
213
+ }
214
+
215
+ }
216
+
217
+ }
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+ ```
228
+
229
+
230
+
31
231
  もし、お分りの方がいらっしゃいましたら、お力添えを頂けますと幸いです。
32
232
 
33
233
  よろしくお願い致します。

3

修正

2018/03/18 11:13

投稿

stringA
stringA

スコア19

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- *カラムとの間にスペースを入れ、1行に2つのデータ(カラム)を表示させたいです。
27
+ *カラムとの間にスペースを入れ、1行に2つのフィールドデータを表示させたいです。
28
28
 
29
29
 
30
30
 

2

画像の変更

2018/03/18 10:18

投稿

stringA
stringA

スコア19

test CHANGED
@@ -1 +1 @@
1
- 【JavaSE】テーブルにあるカラム「社員番号」と「部署名」をプルダウンに表示させたい。
1
+ 【JavaSE】テーブルにあるカラム「社員番号」と「社員名」をプルダウンに表示させたい。
test CHANGED
@@ -6,21 +6,21 @@
6
6
 
7
7
 
8
8
 
9
- 今回私がやりたいことは、localhost上のテーブルにあるカラム「社員番号」と「部署名」の2つを、下記画像のプルダウンに表示させたいと思っています。
9
+ 今回私がやりたいことは、localhost上のテーブルにあるカラム「社員番号」と「社員名」のフィールドデータを、下記画像のプルダウンに表示させたいと思っています。
10
10
 
11
11
 
12
12
 
13
- ![イメージ説明](e5cb07115c4d61459243c3a7bcab7d79.png)
13
+ ![イメージ説明](4814eb71edf195e9aaf1bdf06b2e8f6a.png)
14
14
 
15
15
 
16
16
 
17
17
  【表示例】
18
18
 
19
- 田中太郎 営業部 
19
+ 1001 田中太郎 
20
20
 
21
- 鈴木健太 企画部
21
+ 1002 鈴木健太
22
22
 
23
- 東条花子 経理部
23
+ 1003 東条花子
24
24
 
25
25
 
26
26
 

1

文章修正

2018/03/18 10:17

投稿

stringA
stringA

スコア19

test CHANGED
@@ -1 +1 @@
1
- 【JavaSE】 テーブルにあるカラム「社員番号」と「部署名」の2つ、下記画像のプルダウンに表示させたい。
1
+ 【JavaSE】テーブルにあるカラム「社員番号」と「部署名」をプルダウンに表示させたい。
test CHANGED
File without changes