尽展体育的魅力,创造历史辉煌!2008让我们为奥运加油,为中国加油!
 
 奥运金牌榜
  
  高级搜索
  首页   技术论坛   博客   产品中心   资源中心   银弹在线   商城  


 [无发表权] 请登录或者注册          版主: jiaoly



读写二进制图片    
#1楼
给作者发送短消息 给作者发送短消息 实名会员 商务会员 
查看用户其他信息
总分 2844 分
财富 3070 goCom币
威望 54
排名 第 79 名
段位 新手必读

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

<%
java.sql.Connection conn;
//java.lang.String strConn;
java.sql.PreparedStatement preparedStmt;
java.sql.ResultSet sqlRst;

try {
//javax.naming.InitialContext ctx = new javax.naming.InitialContext();
//javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:/comp/env/jdbc/myoracle");
//conn = ds.getConnection();
try {
    Class.forName("oracle.jdbc.driver.OracleDriver");//.newInstance();
    }catch(ClassNotFoundException e) {
    System.err.print("ClassNotFoundException");
    }
    String url="jdbc:oracle:thin:@localhost:1521:eBiz";     //其中eBiz为SID
String uid="hr";
String pwd="hr";
    conn = DriverManager.getConnection(url,uid,pwd);

String filelocation = request.getParameter("file_name");
File files = new File(filelocation);
FileInputStream fis = new FileInputStream(files);

preparedStmt = conn.prepareStatement("INSERT INTO pictures(pic_name,data) VALUES(?,?)");
preparedStmt.setString(1,request.getParameter("pic_name"));
preparedStmt.setBinaryStream(2, fis, (int)files.length());
preparedStmt.executeUpdate();

fis.close();
preparedStmt.close();
conn.close();
out.println("操作成功!");

} catch (java.sql.SQLException e) {
out.println(e.toString());
}
%>

 


########################################################################################
<%@ page contentType="text/html; charset=gb2312" import="java.sql.*,java.io.*" %>
<html>
<head><title>Show Pictures</title></head>
<body bgcolor="#FFFFFF" text="#000000">
<table>
<%
 int i=1; 
 while (i<3) {
  String srcstring="http://localhost:8080"+   request.getContextPath()+"/showImage?photo_name="+   Integer.toString(i)
%>

 

 
 




发表回复
账号用户名   密码   登录
内容:url email imgsrc image code quote
范例 Example
bold italic underline linethrough   


 [更多...]