| String sql = "intsert into tbl_User values(?, ?)"; PreparedStatement pstmt = con.prepareStatement(sql) ; File file = new File("C:/images/photo.jpg") ; FileInputStream fis = new FileInputStream(file); pstmt.setString(1, "John"); pstmt.setBinaryStream(2, fis, (int)file.length()); pstmt.executeUpdate(); pstmt.close(); fis.close(); |
| String sql = "select photo from tbl_User where username = ?"; PreparedStatement pstmt = con.prepareStatement(selectSQL) ; pstmt.setString(1, "John"); ResultSet rs = pstmt.executeQuery() ; rs.next(); Blob blob = rs.getBlob("photo") ; ImageIcon icon = new ImageIcon(blob.getBytes(1, (int)blob.length())) ; JLabel photo = new JLabel(icon); rs.close(); pstmt.close(); |
| String sql = "insert into tbl_Articles values(?,?)"; PreparedStatement pstmt = con.prepareStatement(sql) ; File file = new File("C:/data/news.txt") ; FileInputStream fis = new FileInputStream(file); pstmt.setString(1, "Iraq War"); pstmt.setAsciiStream(2, fis, (int)file.length()); pstmt.executeUpdate(); pstmt.close(); fis.close(); |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/374079/viewspace-132117/ ,如需转载,请注明出处,否则将追究法律责任。