0

friends,,
i wanna resize the image with specific dimensions while retrieving from database
here is my code
help me

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %> 

<% 
 Connection connection = null;
ResultSet rs = null;
PreparedStatement psmnt = null;
InputStream sImage;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
connection = DriverManager.getConnection("jdbc:odbc:ravi", "system", "system");
psmnt = connection.prepareStatement("SELECT image FROM inimage ");
rs = psmnt.executeQuery();
if(rs.next()) {
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
}
}
catch(Exception ex){
out.println("error :"+ex);
}
finally {
rs.close();
psmnt.close();
connection.close();
}
%>

Edited by __avd: Added [code] tags.

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by peter_budo
0

You want to do this database connection in servlet and there is also place where you can call on a function that will do resizing

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.