数据库存取文本和图片 正在做一个东西,要将文本和图片存储在数据库中,也要求文本和图片同时存储在数据库中,就是说一个要求存取的内容是图文并茂的。大家有人做过的给我点JAVA的示例代码让我学习下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 前段时间做过将图片和文本放到mysql中去记得我是用preparedStatement.setBinaryStream(pra,value)这个方法放到数据库中去的具体我也忘了......... 应该可以用blob类型存储图片,用text类型存文字吧. 楼主可以将图片和附件等存储在文件夹中,然后将像编辑网页一样编辑你所要发表的文章,将生成的html代码存入数据库。我以前做过一个新闻发布系统就是采用的这样的方法,效果挺不错的。你可以自己用JS和JSP写一个文本编辑器。 这个不难吧,数据库都支持二进制的数据的,至于图文并茂,你写个WORD文档,加上文字和图片,再通过流的形式存入数据库即可以SQL2000为例://写入数据库...InputStream in;int length;in = .....;.........PreparedStatement statement = Connect.prepareStatement("update TABLE set content=?");statement.setBinaryStream(1,in,length);statement.executeUpdate();statement.close();.......//从数据库读出来Statement state = .......;OutputStream out = ........;ResultSet Rs = state.executeQuery("select content from TABLE);if( Rs.next() ){ InputStream inword = Rs.getBinaryStream(1); if( inword != null){ byte[] buf = new byte[2048]; while( true ){ int nread = inword.read( buf ); if( nread != -1 ) out.write( buf , 0 , nread ); else break; } } inword.close();}out.flush();out.close();Rs.close();state.close();要是不行的话就google下"word存入数据库" lz可以试试7楼说的,我刚做过,这对全文检索也很有好处---------------------------------------------------------Quietly through .... FormFile file = (FormFile) imageForm.get("file"); byte[] data = file.getFileData();image.setImage(CommonsFiend.base64CodeByteTo64String(data));image.setText((String)imageForm.get("text"));imageinfoDao.insertImages(image);//jdbc插入操作我是这样做的. FormFile file = (FormFile) imageForm.get("file"); byte[] data = file.getFileData();image.setImage(CommonsFiend.base64CodeByteTo64String(data));image.setText((String)imageForm.get("text"));imageinfoDao.insertImages(image);//jdbc插入操作我是这样做的. FormFile file = (FormFile) imageForm.get("file"); byte[] data = file.getFileData();image.setImage(CommonsFiend.base64CodeByteTo64String(data));image.setText((String)imageForm.get("text"));imageinfoDao.insertImages(image);//jdbc插入操作我是这样做的. 你存进去的时候是什么格式,取出来就是什么格式,word就是图文并茂的,不晓得你要存的图文并茂是个什么样子,网页文件吗? 怎样使一个图形界面类关闭之后再进行后续的操作? 希望高手帮我改错 一个新学的聊天程序 大家好,我是新来的,想问关于JAVA学习的东西 请问〉在for语句中定义变量哪一个更好些? 急切寻找合作者!!! 收集应用JAVA程序访问 Berkeley DB 的资料!急! 关于二维数组 高手请进!!!!!!!!!!!!!!!! 棘手的问题求解,在线急等! 强烈抗议微软阻击Java , 强烈投诉,微软这小子老是阳痿 面试题 [求助]有个疑问
将图片和文本
放到mysql中去
记得我是用preparedStatement.setBinaryStream(pra,value)
这个方法放到数据库中去的
具体我也忘了.........
以SQL2000为例://写入数据库
...
InputStream in;
int length;
in = .....;
.........
PreparedStatement statement = Connect.prepareStatement("update TABLE set content=?");
statement.setBinaryStream(1,in,length);
statement.executeUpdate();
statement.close();
.......//从数据库读出来
Statement state = .......;
OutputStream out = ........;
ResultSet Rs = state.executeQuery("select content from TABLE);if( Rs.next() ){
InputStream inword = Rs.getBinaryStream(1);
if( inword != null){
byte[] buf = new byte[2048];
while( true ){
int nread = inword.read( buf );
if( nread != -1 )
out.write( buf , 0 , nread );
else break;
}
}
inword.close();
}
out.flush();
out.close();
Rs.close();
state.close();要是不行的话就google下"word存入数据库"
---------------------------------------------------------
Quietly through ....
FormFile file = (FormFile) imageForm.get("file");
byte[] data = file.getFileData();
image.setImage(CommonsFiend.base64CodeByteTo64String(data));
image.setText((String)imageForm.get("text"));
imageinfoDao.insertImages(image);//jdbc插入操作我是这样做的.
FormFile file = (FormFile) imageForm.get("file");
byte[] data = file.getFileData();
image.setImage(CommonsFiend.base64CodeByteTo64String(data));
image.setText((String)imageForm.get("text"));
imageinfoDao.insertImages(image);//jdbc插入操作我是这样做的.
FormFile file = (FormFile) imageForm.get("file");
byte[] data = file.getFileData();
image.setImage(CommonsFiend.base64CodeByteTo64String(data));
image.setText((String)imageForm.get("text"));
imageinfoDao.insertImages(image);//jdbc插入操作我是这样做的.