【发布时间】:2015-06-24 08:20:09
【问题描述】:
我的手机中保存了一张图片,使用的是 android 4.4。
在(图像的)属性中显示位置:“/storage/emulated/0/bluetooth/p.png”。
现在,问题是,我想通过我的 android 应用程序将此图像 (p.png) 上传到远程 mysql 数据库。它有一个名为 photos 的字段,并被定义为 blob。
我正在尝试此代码。但我不工作。它不会给我一个错误,但唱机永远不会出现在我的数据库表中。 (与数据库的连接OK)。
public void setImage() throws Exception
{
crearConexion();
System.out.println("Entre");
String q="insert into clientes(imagen) values (?) where id_cliente=1;";
try {
String filePath = "/storage/emulated/0/bluetooth/p.png";
InputStream inputStream = new FileInputStream(new File(filePath));
PreparedStatement statement = con.prepareStatement(q);
statement.setBlob(1, inputStream);
statement.executeUpdate();
System.out.println("Terminee");}
catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("ERROR SQLlogHA");
} finally {
}
}
所以请举例说明如何在我的手机中上传照片并使用blob fild将ir保存在mysql远程数据库中。
【问题讨论】: