前提・実現したいこと
Javaでシステム開発をしているのですが、SQLServerを使用しデータを取り出したいです。
いま問題となっているのはストアドプロシージャでの結果取得についてです。
私自身前任者から引き継いだばかりのプログラム初心者な上SQLのことはわかりませんので、
本当に申し訳ないですが状況説明すら間違えてる可能性があります。
やりたいことは、
SQLに名簿があり
ストアドプロシージャを実行すると条件にあった人物が表示されるというものです。
発生している問題・エラーメッセージ
SQLManagementStudio上でストアドプロシージャ実行し、条件にあった検索結果は出て、returnVolumeが0となっています。
上司はSQLは出来るのですがJavaは出来きず、私が未熟なので結果テーブルが取り出せません。
該当のソースコード
SQL側
1USE [Dcat] 2GO 3/****** Object: StoredProcedure [dbo].[getExamineeRs] Script Date: 2018/11/22 15:30:16 ******/ 4SET ANSI_NULLS ON 5GO 6SET QUOTED_IDENTIFIER ON 7GO 8 9-- ============================================= 10-- Author: <Author,,Name> 11-- Create date: <Create Date,,> 12-- Description: <Description,,> 13-- ============================================= 14ALTER PROCEDURE [dbo].[getExamineeRs] 15 -- Add the parameters for the stored procedure here 16 @p_name as nvarchar(50) = null, 17 @p_kananame as nvarchar(50) = null, 18 @p_birth as date = null 19 20AS 21BEGIN 22 -- SET NOCOUNT ON added to prevent extra result sets from 23 -- interfering with SELECT statements. 24 SET NOCOUNT ON; 25 26 -- Insert statements for procedure here 27 28 declare @return int 29 set @return = 0 30 31 select @p_name = ltrim(rtrim(@p_name)) 32 33 if (@p_name is null) and (@p_kananame is null) and (@p_birth is null) begin 34 --SELECT 35 -- [ExamineeId] 36 -- ,[ImportGroupId] 37 -- ,[ResidentNumber] 38 -- ,[ApoDate] 39 -- ,[TestDate] 40 -- ,[Name] 41 -- ,[KanaName] 42 -- ,[Gender] 43 -- ,[Birth] 44 -- ,[Age] 45 -- ,[RankId] 46 -- ,[LastTestId] 47 -- ,[Status] 48 -- ,[DeleteFlag] 49 -- ,[CreateDate] 50 -- ,[CreateUser] 51 -- ,[UpdateDate] 52 -- ,[UpdateUser] 53 -- FROM [dbo].[MExaminee] 54 55 set @return = 200 56 57 end else begin 58 if (@p_name is not null) and (@p_kananame is not null) and (@p_birth is not null) begin 59 select 60 [ExamineeId] 61 ,[ImportGroupId] 62 ,[ResidentNumber] 63 ,[ApoDate] 64 ,[TestDate] 65 ,[Name] = LTRIM(RTRIM([Name])) 66 ,[KanaName] = LTRIM(RTRIM([KanaName])) 67 ,[Gender] 68 ,[Birth] 69 ,[Age] 70 ,[RankId] 71 ,[LastTestId] 72 ,[Status] 73 ,[DeleteFlag] 74 ,[CreateDate] 75 ,[CreateUser] 76 ,[UpdateDate] 77 ,[UpdateUser] 78 FROM [dbo].[MExaminee] 79 where 80 [Name] = @p_name 81 and [KanaName] = @p_kananame 82 and [Birth] = @p_birth 83 end else begin 84 if (@p_name is not null) and (@p_kananame is not null) begin 85 select 86 [ExamineeId] 87 ,[ImportGroupId] 88 ,[ResidentNumber] 89 ,[ApoDate] 90 ,[TestDate] 91 ,[Name] = LTRIM(RTRIM([Name])) 92 ,[KanaName] = LTRIM(RTRIM([KanaName])) 93 ,[Gender] 94 ,[Birth] 95 ,[Age] 96 ,[RankId] 97 ,[LastTestId] 98 ,[Status] 99 ,[DeleteFlag] 100 ,[CreateDate] 101 ,[CreateUser] 102 ,[UpdateDate] 103 ,[UpdateUser] 104 FROM [dbo].[MExaminee] 105 where 106 [Name] = @p_name 107 and [KanaName] = @p_kananame 108 -- and [Birth] = @p_birth 109 end else begin 110 if (@p_name is not null) and (@p_birth is not null) begin 111 select 112 [ExamineeId] 113 ,[ImportGroupId] 114 ,[ResidentNumber] 115 ,[ApoDate] 116 ,[TestDate] 117 ,[Name] = LTRIM(RTRIM([Name])) 118 ,[KanaName] = LTRIM(RTRIM([KanaName])) 119 ,[Gender] 120 ,[Birth] 121 ,[Age] 122 ,[RankId] 123 ,[LastTestId] 124 ,[Status] 125 ,[DeleteFlag] 126 ,[CreateDate] 127 ,[CreateUser] 128 ,[UpdateDate] 129 ,[UpdateUser] 130 FROM [dbo].[MExaminee] 131 where 132 [Name] = @p_name 133 -- and [KanaName] = @p_kananame 134 and [Birth] = @p_birth 135 end else begin 136 if (@p_kananame is not null) and (@p_birth is not null) begin 137 select 138 [ExamineeId] 139 ,[ImportGroupId] 140 ,[ResidentNumber] 141 ,[ApoDate] 142 ,[TestDate] 143 ,[Name] = LTRIM(RTRIM([Name])) 144 ,[KanaName] = LTRIM(RTRIM([KanaName])) 145 ,[Gender] 146 ,[Birth] 147 ,[Age] 148 ,[RankId] 149 ,[LastTestId] 150 ,[Status] 151 ,[DeleteFlag] 152 ,[CreateDate] 153 ,[CreateUser] 154 ,[UpdateDate] 155 ,[UpdateUser] 156 FROM [dbo].[MExaminee] 157 where 158 -- [Name] = @p_name 159 [KanaName] = @p_kananame 160 and [Birth] = @p_birth 161 end else begin 162 if (@p_name is not null) begin 163 select 164 [ExamineeId] 165 ,[ImportGroupId] 166 ,[ResidentNumber] 167 ,[ApoDate] 168 ,[TestDate] 169 ,[Name] = LTRIM(RTRIM([Name])) 170 ,[KanaName] = LTRIM(RTRIM([KanaName])) 171 ,[Gender] 172 ,[Birth] 173 ,[Age] 174 ,[RankId] 175 ,[LastTestId] 176 ,[Status] 177 ,[DeleteFlag] 178 ,[CreateDate] 179 ,[CreateUser] 180 ,[UpdateDate] 181 ,[UpdateUser] 182 FROM [dbo].[MExaminee] 183 where 184 [Name] = @p_name 185 -- [KanaName] = @p_kananame 186 -- and [Birth] = @p_birth 187 end else begin 188 if (@p_kananame is not null) begin 189 select 190 [ExamineeId] 191 ,[ImportGroupId] 192 ,[ResidentNumber] 193 ,[ApoDate] 194 ,[TestDate] 195 ,[Name] = LTRIM(RTRIM([Name])) 196 ,[KanaName] = LTRIM(RTRIM([KanaName])) 197 ,[Gender] 198 ,[Birth] 199 ,[Age] 200 ,[RankId] 201 ,[LastTestId] 202 ,[Status] 203 ,[DeleteFlag] 204 ,[CreateDate] 205 ,[CreateUser] 206 ,[UpdateDate] 207 ,[UpdateUser] 208 FROM [dbo].[MExaminee] 209 where 210 -- [Name] = @p_name 211 [KanaName] = @p_kananame 212 -- and [Birth] = @p_birth 213 end else begin 214 if (@p_birth is not null) begin 215 select 216 [ExamineeId] 217 ,[ImportGroupId] 218 ,[ResidentNumber] 219 ,[ApoDate] 220 ,[TestDate] 221 ,[Name] = LTRIM(RTRIM([Name])) 222 ,[KanaName] = LTRIM(RTRIM([KanaName])) 223 ,[Gender] 224 ,[Birth] 225 ,[Age] 226 ,[RankId] 227 ,[LastTestId] 228 ,[Status] 229 ,[DeleteFlag] 230 ,[CreateDate] 231 ,[CreateUser] 232 ,[UpdateDate] 233 ,[UpdateUser] 234 FROM [dbo].[MExaminee] 235 where 236 -- [Name] = @p_name 237 -- [KanaName] = @p_kananame 238 [Birth] = @p_birth 239 end 240 end 241 end 242 end 243 end 244 end 245 end 246 end 247 248 return (@return) 249END 250 251
Java側
1 2 try { 3 ResultSet rs = Sql.exec(true, "getExamineeRs", params.name, params.kanaName, params.birth); 4 DataTable tbl = new DataTable(rs); 5 6// DataTable tbl = new DataTable("MExaminee"); 7 tbl.setLabelMap( 8 "Name", "名前", 9 "KanaName", "フリガナ", 10 "Birth", "生年月日", 11 "Gender", "性別", 12 "ExamineeId", "ID" 13 ); 14 tbl.addHtml(0, "<td><input type=\"button\" value=\"選択\" onclick=\"rowClick(this);\"></td>"); 15 out.write(tbl.getTable()); 16 17 } catch (SQLException e) { 18 throw new UserRuntimeException(e); 19 }
試したこと
上司は出来るということなので、
色々調べてたのですが、returnVolume以外を取り出す方法がわかりませんでした。
追記
ここで質問したあと3日ほど調べていたら上司の説明通り
「SELECT結果とReturn値の両方を返すストアドからの値取得」が出来るみたいなので頑張っていました。
http://new-pill.hatenablog.com/entry/2017/01/27/174113
しかし、いくらやってもやはり出てきませんでした。(自分が下手なせいかもしれませんが
補足情報(FW/ツールのバージョンなど)
Java1.8
SQLServer2017
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/27 04:51