Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 jsp如何把图片和媒体文件存入oracle中
chengbd



版主


发贴: 687
积分: 112
于 2004-06-21 10:54 user profilesend a private message to usersend email to chengbdsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一步:建立数据库
create table test_img(
id number(4),
name varchar(20),
img long raw);

第二步:
<html><head><title>添加图片</title></head>
<body>
添加图片<br>
<form method="post" action="insertNews.jsp">
图像ID:<input name="id" size="10">
<br>
选择图像:<input type="file" name="image">
<br>
<input type="submit" value="上传" name="submit" size="25">
<input type="reset" value="清除" name="clear" size="25">
<br>
</form>
</body></html>

第三步:插入数据库(InsertImg.jsp)

<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%>

<%
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@lubin:1521:b2bdb";
Connection con=DriverManager.getConnection(url,"demo","demo");

//插入数据库
String sql="insert into test_img values (?,?,?)";
//获取传值ID
String id=request.getParameter("id");
//获取image的路径
String kk=request.getParameter("image");
//转换成file格式
File filename=new File(kk);

//将文件的长度读出,并转换成Long型
long l1=filename.length();
int l2=(int)l1;

//以流的格式赋值
FileInputStream fis=new FileInputStream(filename);

PreparedStatement ps =con.prepareStatement(sql);
ps.setString(1,id);
ps.setString(2,filename.getName());
ps.setBinaryStream(3,fis,l2);
ps.executeUpdate();
ps.close();
fis.close();
看不懂请提出来


why edited on 2004-06-21 11:39


话题树型展开
人气 标题 作者 字数 发贴时间
4532 jsp如何把图片和媒体文件存入oracle中 chengbd 1537 2004-06-21 10:54

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923