更新時(shí)間:2022-08-26 10:53:32 來源:動(dòng)力節(jié)點(diǎn) 瀏覽2212次
Java文件流轉(zhuǎn)為文件的代碼是什么?動(dòng)力節(jié)點(diǎn)小編來告訴大家。
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"));//本意是這個(gè)地方是一個(gè)圖片,在數(shù)據(jù)庫中的格式是Blob類型,希望能轉(zhuǎn)換成File類型,放在user對象中 }
} catch (Exception e) {
e.printStackTrace();
}
try {
pstmt.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
//如何將Blob類型的數(shù)據(jù),放在user對象中
相關(guān)閱讀
初級(jí) 202925
初級(jí) 203221
初級(jí) 202629
初級(jí) 203743