当blob列在db上具有空值时,我遇到了getBinaryStream方法的问题,这是我的代码:
public void getAderent(int id ) throws IOException{
String rq_getAdrent ="SELECT * FROM gss_aderent WHERE ad_id= '"+id+"' ";
Image img=null;
try {
dbConnection db = new dbConnection();
Connection connect = db.connectiondb();
connect.setAutoCommit(false);
Statement stmt= connect.createStatement();
ResultSet rs = stmt.executeQuery(rq_getAdrent);
int i=0;
while(rs.next())
{
addadh_id.setText(rs.getInt("ad_id")+"");
addadh_prenom.setText( rs.getString("ad_fname"));
addadh_nom.setText(rs.getString("ad_lname"));
if(rs.getString("ad_sexe").equals("f")) addadh_sexe.setSelected(true);
addadh_ddn.setText(rs.getString("ad_ddn"));
addadh_adresse.setText(rs.getString("ad_adresse"));
addadh_mobile.setText(rs.getString("ad_mobile"));
addadh_email.setText(rs.getString("ad_email"));
addadh_sante.setValue(rs.getString("ad_sante"));
addadh_taille.setText(rs.getDouble("ad_taille")+"");
addadh_poids.setText(rs.getDouble("ad_poids_initial")+"");
addadh_urgence_contact.setText(rs.getString("ad_urgence_contact"));
if(rs.getBinaryStream("ad_photo") != null)
img = new Image(rs.getBinaryStream("ad_photo"));
else
img = new Image("proson.png" );
addadh_adherent_photo.setImage(img);
addadh_adherent_photo_label.setText("photo définie");
}
rs.close();
stmt.close();
connect.commit();
connect.close();
// msg.showMsg(stage, "information", "Information", "Vous avez selectionné l'adérent numéro : "+id);
} catch (SQLException ex) {
Logger.getLogger(Cons_aderentController.class.getName()).log(Level.SEVERE, null, ex);
}
}
我得到了这个例外:
Executing D:\backup\NetBeansProjects\JavaFx Projects\GssPro\dist\run1860540670\GssPro.jar using platform C:\Program Files\Java\jdk1.8.0_31\jre/bin/java
avr. 14, 2015 2:13:48 PM javafx.scene.control.Control loadSkinClass
SEVERE: No valid constructor defined in 'com.sun.javafx.scene.control.skin.ComboBoxBaseSkin' for control ComboBox[id=addadh_sante, styleClass=combo-box-base combo-box].
You must provide a constructor that accepts a single Skinnable (e.g. Control or PopupControl) parameter in com.sun.javafx.scene.control.skin.ComboBoxBaseSkin.
avr. 14, 2015 2:13:48 PM javafx.scene.control.Control loadSkinClass
SEVERE: No valid constructor defined in 'com.sun.javafx.scene.control.skin.ComboBoxBaseSkin' for control ComboBox[id=addadh_sante, styleClass=combo-box-base combo-box].
You must provide a constructor that accepts a single Skinnable (e.g. Control or PopupControl) parameter in com.sun.javafx.scene.control.skin.ComboBoxBaseSkin.
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1762)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1645)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3437)
at javafx.scene.Scene$ClickGenerator.access$7900(Scene.java:3365)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3733)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3452)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1728)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2461)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:348)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:273)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:382)
at com.sun.glass.ui.View.handleMouseEvent(View.java:553)
at com.sun.glass.ui.View.notifyMouse(View.java:925)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/584634336.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1759)
... 30 more
Caused by: java.lang.NullPointerException
at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106)
at org.sqlite.jdbc3.JDBC3ResultSet.getBinaryStream(JDBC3ResultSet.java:235)
at org.sqlite.jdbc3.JDBC3ResultSet.getBinaryStream(JDBC3ResultSet.java:242)
at controllers.Cons_aderentController.getAderent(Cons_aderentController.java:134)
at controllers.Cons_aderentController.initData(Cons_aderentController.java:92)
at controllers.Maj_aderentController.ConsultAderent(Maj_aderentController.java:177)
... 40 more
当db上的行没有blob列的空值时,一切都很好,但问题是当行具有空值时。我该如何解决这个问题?
PS:Cons_aderentController.java:134对应于:if(rs.getBinaryStream("ad_photo") != null)
答案 0 :(得分:0)
假设列名正确并且该列真正包含SQL NULL
值(我认为这是给出描述的唯一可能性),那么看起来您的JDBC驱动程序没有正确实现{{1 }} 在这种情况下。 (我不是sqlite用户,但看起来这可能是known bug。)
作为(丑陋的)解决方法,请尝试
ResultSet