注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 一个黑客与一个电脑白痴的..
 帮助

使用Java实现在SQLserver中实现图片的存储


2008-04-22 19:58:00
 标签:Java SQLserver   [推送到技术圈]

使用Java实现在SQLserver中实现图片的存储

Connection conn = null;
try{
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://IP:1433;DataBaseName=Moftec","sa","mymm");
}
catch(Exception e )
{
//捕捉异常并抛出IOException
out.println("Can not connec to the database! The exception is " + e.toString());
}
FileInputStream fis=null;
File file = new File("E:/java/chart.jpg");
try{
fis = new FileInputStream(file);
}catch(FileNotFoundException e){
out.println("Not find file!");
}
PreparedStatement ps = conn.prepareStatement("Insert into gs_img (lei,years,img) values (?,?,?)");
ps.setString(1,"ivan");
ps.setInt(2,4);
ps.setBinaryStream(3,fis,(int)file.length());
ps.executeUpdate();
ps.close();
try{
fis.close();
out.println("写进去了!");
}catch(IOException e){
out.println("fis cann't cloase!");
}




    文章评论
 
2008-05-26 13:32:33
之前看过你blog中很多关于SAP的东东,呵呵……

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: