私は以下のような形をしています。
++++++++++++++++++++++++++++++++++++++++++++++++++
+ Id : TextBox +
+ Name : TextBox +
+ Mob : TextBox +
+ Photo : File Option +
+ +
+ Submit Update +
++++++++++++++++++++++++++++++++++++++++++++++++++
私がやりたいことは、それぞれの ID のデータを更新することです。更新のために、以下のようなクエリがあります。
PreparedStatement pst = conn.prepareStatement("UPDATE myTable SET name=?, mob=?, photo=? WHERE id=?");
pst.setString(1, personName);
pst.setString(2, mobileNum);
pst.setBinaryStream(3, InputStreamData);
pst.setString(4, personId);
pst.executeUpdate();
問題があります。シナリオ付きで説明します。
id が 1 で、personName と file のデータが既にあるとします。今は携帯番号のみ入力しています。. どうすれば発言を避けることができpst.setBinaryStream(4, InputStreamData);
ますか? データが既に存在するため、データを入力したくありません。データを挿入できる SQL ステートメントはありますか。
名前データのみを事前入力できますが、ファイル データは事前入力できません。
編集 1
これに対する解決策は、多数の UPDATE ステートメントを使用することです。しかし、問題は私が多くのフィールドを持っていることです。そんなに多くの UPDATE ステートメントを使用することはできません。
編集 2
私が試したのは、写真データを読み取り、そのデータを以下のように setBinaryStream に設定することです。
pst.setBinaryStream(4, rst.getBinaryStream(1));
しかし、それは私にエラーを与えます
java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
javax.faces.el.EvaluationException: java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
--
Caused by: java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
at com.sac.databean.PersonalInformationDataBean.editPersonalInfo(PersonalInformationDataBean.java:1530)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:779)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:528)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257)