jsp中圖片處理相關操作
來源:互聯網
上載者:User
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*"%>
<html>
<body>
<%
/*
drop table imagetable;
create table imagetable
(
nid int not null,
image blob,
primary key (nid)
)
type = InnoDB;
*/
/*
//================ 一 、將檔案寫入到資料庫的大欄位中begin=====================
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/test?user=root&password=eastsoftweb";
Connection conn= DriverManager.getConnection(url);
java.io.File file = new File("d:/temp/1.jpg");
FileInputStream is=new FileInputStream(file);
PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO imagetable (nid,image)" +
"VALUES (?, ?)"); //先行編譯SQL語句
stmt.setInt(1, 1);
stmt.setBinaryStream(2, is,(int)file.length());
stmt.executeUpdate();
stmt.close();
is.close();
out.println("update end");
//===============將檔案寫入到資料庫的大欄位中end=========================
*/
/*
//====================== 二、jsp顯示伺服器硬碟圖片樣本 begin==============