- All Known Implementing Classes:
- SerialBlob
- See Also:
- Top Examples, Source Code,
PreparedStatement
, CallableStatement
, ResultSet
InputStream getBinaryStream()
throws SQLException
- See Also:
setBinaryStream(long)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
byte[] getBytes(long pos,
int length)
throws SQLException
- See Also:
setBytes(long, byte[])
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[694]BLOB Download Servlet
By Anonymous on 2004/03/08 19:18:24 Rate
public class BLOBDownloadServlet extends HttpServlet {
private String dbUrl = "jdbc:mysql://localhost/myapp";
private String jdbcDriver = "com.mysql.jdbc.Driver";
protected void doGet ( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
ServletOutputStream out = response.getOutputStream ( ) ;
int id = Integer.parseInt ( request.getParameter ( "id" ) ) ;
response.setContentType ( "image/jpeg" ) ;
out.write ( getBlob ( id ) ) ;
out.flush ( ) ;
out.close ( ) ;
}
public byte [ ] getBlob ( int id ) {
String sqlQuery = "SELECT blobfield FROM BLOBTABLE WHERE ID = ?;";
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Blob blob = null;
byte [ ] bytes = null;
String description = "";
try {
Class.forName ( jdbcDriver ) ;
con = DriverManager.getConnection ( dbUrl ) ;
pstmt = con.prepareStatement ( sqlQuery ) ;
pstmt.setInt ( 1,id ) ;
rs = pstmt.executeQuery ( ) ;
ResultSetMetaData md = rs.getMetaData ( ) ;
while ( rs.next ( ) ) {
blob = rs.getBlob ( 1 ) ;
}
bytes = blob.getBytes ( 1, ( int ) ( blob.length ( ) ) ) ;
con.close ( ) ;
}
catch ( ClassNotFoundException e ) {
e.printStackTrace ( ) ;
}
catch ( SQLException e ) {
e.printStackTrace ( ) ;
}
return bytes;
}
}
long length()
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
long position(byte[] pattern,
long start)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
long position(Blob pattern,
long start)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
OutputStream setBinaryStream(long pos)
throws SQLException
- See Also:
getBinaryStream()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int setBytes(long pos,
byte[] bytes)
throws SQLException
- See Also:
getBytes(long, int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
int setBytes(long pos,
byte[] bytes,
int offset,
int len)
throws SQLException
- See Also:
getBytes(long, int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void truncate(long len)
throws SQLException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples