public class DBGifReader extends HttpServlet { public void init() throws ServletException { }
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { OutputStream out = res.getOutputStream(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection ("Jdbc:Odbc:Autoweb");
Statement stmt = con.createStatement();
res.setContentType("image/gif");
ResultSet rs = stmt.executeQuery("SELECT * FROM Billede;");
byte[] buff = new byte[4096];
while (rs.next()) { /*File file = new File("C:\\Programmer\\Apache Tomcat 4.0\\webapps\\ROOT\\Autoweb\\a.gif"); FileInputStream fin = new FileInputStream(file);*/
InputStream fin = rs.getBinaryStream(1);
for (;;) { int size = fin.read(buff);
if (size == -1) break;
out.write(buff, 0, size); } } }
catch(Exception e) { } } }
if i show the picture direct from af file it works just fine, but the intension is to have the image stored in a database.
No exception is thrown, but can it be corsed by microsoft access database?
My best guess that it goes wrong in the getBinaryStream Allthou, i have testet the contest og the stream, and every thing seems to be good. but its just wird that its ok when i get the picture direct from c:, but not from the database.