java web项目中如何将上传图片的路径存到mysql?希望有实际代码例子,感谢!
数据库加个保存路径的字段,set进去保存不就好了
文件上传后获取上传地址,后实例化数据库
http://www.cnblogs.com/warrior4236/p/5682830.html
http://blog.csdn.net/qq_34309305/article/details/66968584
这里实现了有代码,有结果图
按理说你不应该会有这样的疑问:1.你在上传图片时,用面向对象的思想写代码的话,图片对象你应该做过封装:她该有的属性你应该都有:比如: 图片的路径imgpath。。。.你都应该获得的到。
public static boolean update(String imapath/*List u*/){
Connection conn=UtilDb.getConn();//数据库连接类,自己可直接写
PreparedStatement ps=null;
try {
ps = conn.prepareStatement("update xxxx set imgurl =? where url !=? and > ?");
ps.setString(1, imapath+".jpg");
ps.executeUpdate();
//ps.addBatch();
//ps.executeBatch();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
UtilDb.closeAll(conn, ps, null);
}
return false;
}
//=========================
这里有上传图片的代码,你后台加个字段就可以了,就像保存普通字段一样:http://blog.csdn.net/xuanzhangran/article/details/54928997
兄弟,你解决了吗?我也是要做java web项目。想要在本地上传图片,把图片路径存入mysql数据库,再从数据库中读取图片并在网页显示。可是不知道如何用代码实现,求大神!