<%@ page contentType="text/htmlcharset=gb2312"%>
<%@ page language="java" import="java.sql.*" %>
<%/////连接数据库
java.sql.Connection conn
java.sql.Statement stmt
java.sql.ResultSet rs1
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
conn=DriverManager.getConnection("jdbc:odbc:dababasename")///数据源
stmt=conn.createStatement()
%>
<%
String sqlin="insert into drawing values
File file = new File("c:/z.jpg")
long l1=file.length()
int l2=(int)l1
FileInputStream is = new FileInputStream(file)
InputStream fis=(InputStream)is
PreparedStatement ps = conn.prepareStatement("insert into images values (?,?)")
ps.setString(1,file.getName())
ps.setBinaryStream(2,fis,file.length())
ps.executeUpdate()
ps.close()
fis.close()
//将图片从数据库中提取,进行显示
//drawing字段为IMAGE类型
stmt = conn.createStatement()
rs1 = stmt.executeQuery("SELECT * FROM drawing WHERE drawing_code ='0-515' and version=3")
if (rs1.next())
{
String dim_image = rs1.getString("file_name")
byte [] blocco = rs1.getBytes("drawing")
response.setContentType("image/jpeg")
ServletOutputStream op = response.getOutputStream()
for(int i=0i<blocco.lengthi++)
{
op.write(blocco[i])
}
}
rs1.close()
%>
首先设置Form的AllowDrop=true
public partial class Form1 : Form{
public Form1()
{
InitializeComponent()
}
private void btnStart_Click(object sender, EventArgs e)
{
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link
}
else
{
e.Effect = DragDropEffects.None
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString()
}
}
在DragDrop事件中能够得到拖放到窗体上的文件路径,然后使用filestream就可以上传了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)