JavaFX、SQLite:如何在更新查询中设置 BLOB 值?
JavaFX,SQLite : How to Set BLOB Value in update Query?
我在执行更新查询时遇到问题,问题是当我想更新我的 sqlite 中的 blob 列时 table,我注意到只有存储此 blob 文件的路径。但是当使用具有绑定值的插入查询时:pst.setBinaryStream(File);
它工作正常!
我用这段代码得到了我的 blob 文件:
File image=null;
URL photoURL = null;
try {
photoURL = new URL(addadh_adherent_photo_label.getText());
} catch (MalformedURLException ex) {
Logger.getLogger(ParametresController.class.getName()).log(Level.SEVERE, null, ex);
}
try {
image= new File( URLDecoder.decode( photoURL.getFile(), "UTF-8" ) );
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(ParametresController.class.getName()).log(Level.SEVERE, null, ex);
}
FileInputStream fis = null;
try {
fis = new FileInputStream(image);
} catch (FileNotFoundException ex) {
Logger.getLogger(ParametresController.class.getName()).log(Level.SEVERE, null, ex);
}
这是我的更新查询:
int AderentId =100;
String updateAderent=" UPDATE gss_aderent SET"
+ "ad_photo='"+image+"'
+ "WHERE ad_id='"+AderentId+"' ";
stmt.executeUpdate(updateAderent);
我的问题是:更新后的值不是 blob 值,而只是他的路径:( 我的问题是如何在更新查询中存储(更新)blob 值?是否存在绑定 BinaryStream 参数以进行更新查询的方法? 我可以在更新查询中使用 preparedStatement 吗?
您的申请似乎对 SQL Injection attacks
开放
使用 PreparedStatement 和 setBlob(int x, InputStream in)
我在执行更新查询时遇到问题,问题是当我想更新我的 sqlite 中的 blob 列时 table,我注意到只有存储此 blob 文件的路径。但是当使用具有绑定值的插入查询时:pst.setBinaryStream(File);
它工作正常!
我用这段代码得到了我的 blob 文件:
File image=null;
URL photoURL = null;
try {
photoURL = new URL(addadh_adherent_photo_label.getText());
} catch (MalformedURLException ex) {
Logger.getLogger(ParametresController.class.getName()).log(Level.SEVERE, null, ex);
}
try {
image= new File( URLDecoder.decode( photoURL.getFile(), "UTF-8" ) );
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(ParametresController.class.getName()).log(Level.SEVERE, null, ex);
}
FileInputStream fis = null;
try {
fis = new FileInputStream(image);
} catch (FileNotFoundException ex) {
Logger.getLogger(ParametresController.class.getName()).log(Level.SEVERE, null, ex);
}
这是我的更新查询:
int AderentId =100;
String updateAderent=" UPDATE gss_aderent SET"
+ "ad_photo='"+image+"'
+ "WHERE ad_id='"+AderentId+"' ";
stmt.executeUpdate(updateAderent);
我的问题是:更新后的值不是 blob 值,而只是他的路径:( 我的问题是如何在更新查询中存储(更新)blob 值?是否存在绑定 BinaryStream 参数以进行更新查询的方法? 我可以在更新查询中使用 preparedStatement 吗?
您的申请似乎对 SQL Injection attacks
开放使用 PreparedStatement 和 setBlob(int x, InputStream in)