java 流转文件_java中如何将流转换成文件类型

StringId=request.getParameter("userId");intuserId=Integer.parseInt(Id);Stringsql="select*fromUserwhereuserId=?";Useru=newUser();DbHelperdb=newDbHelper();Connectionconnect...

String Id = request.getParameter("userId");

int userId = Integer.parseInt(Id);

String sql = "select * from User where userId=?";

User u = new User();

DbHelper db = new DbHelper();

Connection connection = db.getConnection();

ResultSet rs = null;

PreparedStatement pstmt = null;

User u = new User();

try {

pstmt = connection.prepareStatement(sql);

pstmt.setInt(1, userId);

//list = (List)pstmt.executeQuery();

rs = pstmt.executeQuery();

while (rs.next()) {

u.setString(rs.getString("userName"));

u.setFile(rs.getFile("file"));//本意是这个地方是一个图片,在数据库中的格式是Blob类型,希望能转换成File类型,放在user对象中 }

} catch (Exception e) {

e.printStackTrace();

}

try {

pstmt.close();

connection.close();

} catch (Exception e) {

e.printStackTrace();

}

//如何将Blob类型的数据,放在user对象中

展开

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值