紧急问题:如何在JSP+MYSQL 中存入图片 问题是:在Servlet中获取页面文本框里面图片的路径。在存入数据库中 请大家帮帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那要去下个jar包,smartupload百度下就有了 我觉得楼主先应该想清楚要在Mysql中存路径字符串还是存Blob对象? 不至于说在数据库中存图片吧?用blob对象存?为什么不直接存上传后的路径捏.:(package com.hmilyld.exp.mysql;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.sql.Connection;import java.sql.PreparedStatement;public class InsertBLOB { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Connection conn = ConnectionManage.getConnection(); String sql = "insert into testimage(image) values(?)"; PreparedStatement stm = conn.prepareStatement(sql); File file = new File("c:\\aaa.gif"); InputStream photoStream = new FileInputStream(file); stm.setBinaryStream(1, photoStream, (int)file.length()); stm.executeUpdate(); ConnectionManage.closeConnection(conn, null, null); }} 额,楼主的意思好像是要存地址进去,用smartUpload上传,然后获得上传后的路径,存入数据库就OK了.具体的,楼主GG下SmartUpload就能找到了,很多例子的. 将hibernate里的日期数据存入SQL server数据库怎么转换啊? java 无限级递归调用 使用struts2能够分页吗? 急啊!如何实现远程上报功能?高手快进来看看,只要对我有启发的都会给分的 大家给点建议,来者有分,新建一个网站,急急急! WEB出大问题啦!!!!! 有一问题请教:在上载文件时,能否做到上载的文件放在与应用服务器不同的机器上? 请各位给点赐教,来者有分。(在线讨论) struct1.1 的 message resources 如何 解决 中文问题 java 高难度问题,欢迎高手挑战,100分!!!!!!!!!!!!!!!!!!!! 数据采集怎样实现??
百度下就有了
为什么不直接存上传后的路径捏.:(
package com.hmilyld.exp.mysql;import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;public class InsertBLOB { /**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Connection conn = ConnectionManage.getConnection();
String sql = "insert into testimage(image) values(?)";
PreparedStatement stm = conn.prepareStatement(sql);
File file = new File("c:\\aaa.gif");
InputStream photoStream = new FileInputStream(file);
stm.setBinaryStream(1, photoStream, (int)file.length());
stm.executeUpdate();
ConnectionManage.closeConnection(conn, null, null);
}
}
用smartUpload上传,然后获得上传后的路径,存入数据库就OK了.
具体的,楼主GG下SmartUpload就能找到了,很多例子的.