I have form as below.
++++++++++++++++++++++++++++++++++++++++++++++++++
+ Id : TextBox +
+ Name : TextBox +
+ Mob : TextBox +
+ Photo : File Option +
+ +
+ Submit Update +
++++++++++++++++++++++++++++++++++++++++++++++++++
What I want to do is update the data for the respective Id. For update I have query as below.
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();
I have problem. I will explain with scenario.
Suppose id is 1 and I already have data for personName & file. Now I enter mobile number only. . How could I avoid pst.setBinaryStream(4, InputStreamData); statement? I don’t want to enter any data as data is already present. Is there any sql statement where I can insert data.
I can pre-populate only Name data BUT NOT file data.
Edit 1
Solution for this is, have many UPDATE statements. BUT the problem is I have many fields. I can’t use so many UPDATE statements.
Edit 2
What I tried is read the photo data & set that data in setBinaryStream as below.
pst.setBinaryStream(4, rst.getBinaryStream(1));
But it give me ERROR as
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)
pst.setBinaryStream(4, rst.getBinaryStream(1), (int) rst.getString(1).length());did the trick.