質問編集履歴

2

Markdownの修正

2021/01/20 17:11

投稿

gagagagaga
gagagagaga

スコア0

test CHANGED
File without changes
test CHANGED
@@ -285,3 +285,5 @@
285
285
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
286
286
 
287
287
  filters.EncodingFilter.doFilter(EncodingFilter.java:38)
288
+
289
+ よろしくお願い致します。

1

Markdownの修正

2021/01/20 17:11

投稿

gagagagaga
gagagagaga

スコア0

test CHANGED
File without changes
test CHANGED
@@ -1,283 +1,287 @@
1
- Apachetikaを用いてpdfファイル内のテキストを抽出しSQLへの登録を行いたいと考えておりますが、ステートメントを実行できないといったエラーに悩まされております。
1
+ Apachetikaを用いてpdfファイル内のテキストを抽出しSQLへの登録を行いたいと考えておりますがエラーに悩まされております。
2
-
3
-
4
2
 
5
3
  以下コード:
6
4
 
7
5
  ```Java
8
6
 
7
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
8
+
9
+      String _token = (String)request.getParameter("_token");
10
+
11
+ if(_token != null && _token.equals(request.getSession().getId())) {
12
+
13
+ EntityManager re = DBUtil.createEntityManager();
14
+
15
+
16
+
17
+ Report r = new Report();
18
+
19
+
20
+
21
+ r.setName(request.getParameter("name"));
22
+
23
+ r.setAuthor(request.getParameter("author"));
24
+
25
+ r.setYear(request.getParameter("year"));
26
+
27
+ r.setMagazine(request.getParameter("magazine"));
28
+
29
+ r.setDepartment(Integer.parseInt(request.getParameter("department")));
30
+
31
+
32
+
33
+ Part part = request.getPart("avatar");
34
+
35
+ String name = this.getFileName(part);
36
+
37
+ r.setData(name);
38
+
39
+
40
+
41
+ Timestamp currentTime = new Timestamp(System.currentTimeMillis());
42
+
43
+ r.setCreated_at(currentTime);
44
+
45
+ r.setUpdated_at(currentTime);
46
+
47
+ r.setDelete_flag(0);
48
+
49
+
50
+
51
+ List<String> errors = ReportValidator.validate(r, true);
52
+
53
+ if(errors.size() > 0) {
54
+
55
+ re.close();
56
+
57
+
58
+
59
+ request.setAttribute("_token", request.getSession().getId());
60
+
61
+ request.setAttribute("report", r);
62
+
63
+ request.setAttribute("errors", errors);
64
+
65
+
66
+
67
+ RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/reports/new.jsp");
68
+
69
+ rd.forward(request, response);
70
+
71
+ } else {
72
+
73
+ re.getTransaction().begin();
74
+
75
+ name = r.getId() + "_" + name;
76
+
9
- @WebServlet("/reports/create")
77
+ part.write("/Users/---/new/" + name);
10
-
78
+
11
- @MultipartConfig(location="/tmp", maxFileSize=1048576000)
79
+ try {
12
-
80
+
13
- public class ReportsCreateServlet extends HttpServlet {
81
+ AutoDetectParser parser = new AutoDetectParser();
82
+
14
-
83
+ Metadata metaData = new Metadata();
84
+
85
+ ParseContext context = new ParseContext();
86
+
15
- private static final long serialVersionUID = 1L;
87
+ BodyContentHandler handler = new BodyContentHandler();
16
-
17
-
18
-
88
+
19
- /**
89
+ parser.parse(new FileInputStream(new File("/Users/---/new/" + name)), handler, metaData, context);
20
-
90
+
21
- * @see HttpServlet#HttpServlet()
91
+ String ret = handler.toString();
22
-
92
+
23
- */
93
+ r.setSearchdata(ret);
24
-
94
+
25
- public ReportsCreateServlet() {
95
+ } catch (SAXException | TikaException e) {
96
+
26
-
97
+ // TODO 自動生成された catch ブロック
98
+
99
+ e.printStackTrace();
100
+
101
+ }
102
+
103
+ r.setData(name);
104
+
27
- super();
105
+ re.persist(r);
106
+
107
+ re.flush();
108
+
109
+ re.getTransaction().commit();
110
+
111
+ request.getSession().setAttribute("flush", "登録が完了しました。");
112
+
113
+ re.close();
114
+
115
+ response.sendRedirect(request.getContextPath() + "/reports/index");
116
+
117
+ }
118
+
119
+ }
28
120
 
29
121
  }
30
122
 
31
-
32
-
33
- /**
34
-
35
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
36
-
37
- */
38
-
39
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40
-
41
- String _token = (String)request.getParameter("_token");
42
-
43
- if(_token != null && _token.equals(request.getSession().getId())) {
44
-
45
- EntityManager re = DBUtil.createEntityManager();
46
-
47
-
48
-
49
- Report r = new Report();
50
-
51
-
52
-
53
- r.setName(request.getParameter("name"));
54
-
55
- r.setAuthor(request.getParameter("author"));
56
-
57
- r.setYear(request.getParameter("year"));
58
-
59
- r.setMagazine(request.getParameter("magazine"));
60
-
61
- r.setDepartment(Integer.parseInt(request.getParameter("department")));
62
-
63
-
64
-
65
- Part part = request.getPart("avatar");
66
-
67
- String name = this.getFileName(part);
123
+ private String getFileName(Part part) {
68
-
124
+
69
- r.setData(name);
125
+ String name = null;
70
-
71
-
72
-
73
- Timestamp currentTime = new Timestamp(System.currentTimeMillis());
126
+
74
-
75
- r.setCreated_at(currentTime);
76
-
77
- r.setUpdated_at(currentTime);
78
-
79
- r.setDelete_flag(0);
80
-
81
-
82
-
83
- List<String> errors = ReportValidator.validate(r, true);
84
-
85
- if(errors.size() > 0) {
86
-
87
- re.close();
88
-
89
-
90
-
91
- request.setAttribute("_token", request.getSession().getId());
127
+ for (String dispotion : part.getHeader("Content-Disposition").split(";")) {
92
-
128
+
93
- request.setAttribute("report", r);
129
+ if (dispotion.trim().startsWith("filename")) {
94
-
95
- request.setAttribute("errors", errors);
130
+
96
-
97
-
98
-
99
- RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/reports/new.jsp");
131
+ name = dispotion.substring(dispotion.indexOf("=") + 1).replace("\"", "").trim();
100
-
101
- rd.forward(request, response);
132
+
102
-
103
- } else {
104
-
105
- re.getTransaction().begin();
106
-
107
- name = r.getId() + "_" + name;
133
+ name = name.substring(name.lastIndexOf("\") + 1);
108
-
109
- part.write("/Users/---/new/" + name);
134
+
110
-
111
- try {
135
+ break;
112
-
113
- AutoDetectParser parser = new AutoDetectParser();
114
-
115
- Metadata metaData = new Metadata();
116
-
117
- ParseContext context = new ParseContext();
118
-
119
- BodyContentHandler handler = new BodyContentHandler();
120
-
121
- parser.parse(new FileInputStream(new File("/Users/---/new/" + name)), handler, metaData, context);
122
-
123
- String ret = handler.toString();
124
-
125
- r.setSearchdata(ret);
126
-
127
- } catch (SAXException | TikaException e) {
128
-
129
- // TODO 自動生成された catch ブロック
130
-
131
- e.printStackTrace();
132
-
133
- }
134
-
135
- r.setData(name);
136
-
137
- re.persist(r);
138
-
139
- re.flush();
140
-
141
- re.getTransaction().commit();
142
-
143
- request.getSession().setAttribute("flush", "登録が完了しました。");
144
-
145
- re.close();
146
-
147
-
148
-
149
- response.sendRedirect(request.getContextPath() + "/reports/index");
150
136
 
151
137
  }
152
138
 
153
139
  }
154
140
 
141
+ return name;
142
+
155
143
  }
156
144
 
157
- private String getFileName(Part part) {
158
-
159
- String name = null;
160
-
161
- for (String dispotion : part.getHeader("Content-Disposition").split(";")) {
162
-
163
- if (dispotion.trim().startsWith("filename")) {
164
-
165
- name = dispotion.substring(dispotion.indexOf("=") + 1).replace("\"", "").trim();
166
-
167
- name = name.substring(name.lastIndexOf("\") + 1);
168
-
169
- break;
170
-
171
- }
145
+ }
146
+
172
-
147
+ ```
148
+
149
+
150
+
151
+ ```Java
152
+
153
+ @Entity
154
+
155
+ public class Report {
156
+
173
- }
157
+     :
158
+
174
-
159
+ @Lob
160
+
161
+ @Column(name = "searchdata", nullable = false ,length = 1000000000)
162
+
175
- return name;
163
+ private String searchdata;
164
+
165
+    :
176
166
 
177
167
  }
178
168
 
179
169
  }
180
170
 
171
+
172
+
181
173
  ```
182
174
 
183
175
 
184
176
 
185
- ```Java
177
+ ```JSP
186
-
187
-
178
+
188
-
189
- @Entity
190
-
191
- public class Report {
192
-
193
- @Id
194
-
195
- @Column(name = "id")
196
-
197
- @GeneratedValue(strategy = GenerationType.IDENTITY)
198
-
199
- private Integer id;
200
-
201
-
202
-
203
- @Column(name = "name", nullable = false, unique = true)
204
-
205
- private String name;
206
-
207
-
208
-
209
- @Column(name = "author", nullable = false)
210
-
211
- private String author;
212
-
213
-
214
-
215
- @Column(name = "year", nullable = false)
216
-
217
- private String year;
218
-
219
-
220
-
221
- @Column(name = "magazine", nullable = false)
222
-
223
- private String magazine;
224
-
225
-
226
-
227
- @Column(name = "created_at", nullable = false)
179
+ <label for="searchdata"></label>
228
-
229
- private Timestamp created_at;
180
+
230
-
231
-
232
-
233
- @Column(name = "department", nullable = false)
234
-
235
- private Integer department;
181
+ <br /><br />
236
-
237
-
238
-
239
- @Column(name = "data", nullable = false)
182
+
240
-
241
- private String data;
242
-
243
-
244
-
245
- @Lob
246
-
247
- @Column(name = "searchdata", nullable = false ,length = 1000000000)
183
+ <input type="hidden" name="search" value="${report.searchdata}" />
248
-
249
- private String searchdata;
250
-
251
-
252
-
253
- @Column(name = "updated_at", nullable = false)
254
-
255
- private Timestamp updated_at;
256
-
257
-
258
-
259
- @Column(name = "delete_flag", nullable = false)
260
-
261
- private Integer delete_flag;
262
-
263
-
264
-
265
- }
266
-
267
- }
268
-
269
-
270
184
 
271
185
  ```
272
186
 
273
-
187
+ HTTPステータス 500 - org.hibernate.exception.DataException: could not execute statement
274
-
188
+
275
- ```JSP
189
+ type 例外レポート
190
+
191
+
192
+
276
-
193
+ メッセージ org.hibernate.exception.DataException: could not execute statement
194
+
195
+
196
+
197
+ 説明 The server encountered an internal error that prevented it from fulfilling this request.
198
+
199
+
200
+
201
+ 例外
202
+
203
+
204
+
205
+ javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute statement
206
+
207
+ org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149)
208
+
209
+ org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
210
+
211
+ org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
212
+
213
+ org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:789)
214
+
215
+ org.hibernate.internal.SessionImpl.persist(SessionImpl.java:767)
216
+
217
+ controllers.reports.ReportsCreateServlet.doPost(ReportsCreateServlet.java:99)
218
+
277
- <label for="searchdata"></label>
219
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
220
+
278
-
221
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
222
+
223
+ org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
224
+
279
- <br /><br />
225
+ filters.EncodingFilter.doFilter(EncodingFilter.java:38)
226
+
280
-
227
+ 原因
228
+
229
+ org.hibernate.exception.DataException: could not execute statement
230
+
231
+ org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:52)
232
+
233
+ org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
234
+
235
+ org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
236
+
237
+ org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
238
+
239
+ org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:178)
240
+
241
+ org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57)
242
+
243
+ org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)
244
+
245
+ org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2919)
246
+
247
+ org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3490)
248
+
281
- <input type="hidden" name="search" value="${report.searchdata}" />
249
+ org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
250
+
282
-
251
+ org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:636)
252
+
253
+ org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:281)
254
+
255
+ org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:262)
256
+
257
+ org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:316)
258
+
259
+ org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
260
+
261
+ org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
262
+
263
+ org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
264
+
265
+ org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
266
+
267
+ org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)
268
+
269
+ org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
270
+
271
+ org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
272
+
273
+ org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
274
+
275
+ org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:782)
276
+
277
+ org.hibernate.internal.SessionImpl.persist(SessionImpl.java:767)
278
+
279
+ controllers.reports.ReportsCreateServlet.doPost(ReportsCreateServlet.java:99)
280
+
281
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
282
+
283
+ javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
284
+
285
+ org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
286
+
283
- ```
287
+ filters.EncodingFilter.doFilter(EncodingFilter.java:38)