The Artima Developer Community
Sponsored Link

Java Answers Forum
Show picture stored in database

2 replies on 1 page. Most recent reply: Nov 15, 2002 10:55 AM by Palle Jensen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Palle Jensen

Posts: 6
Nickname: palle
Registered: Nov, 2002

Show picture stored in database Posted: Nov 14, 2002 5:52 PM
Reply to this message Reply
Advertisement
Im new in java, so let me explain what im trying to do.

i want to get a picture, stored in a access databse, and then show it on a html page

the code i have looks like this

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

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.

What am i douing wrong?

Yours

Palle


Dharmendra

Posts: 10
Nickname: dh547
Registered: Oct, 2002

Re: Show picture stored in database Posted: Nov 14, 2002 9:15 PM
Reply to this message Reply
I dont see any problem in this.Is it throwing any exception
If so plese send me the trace.

Palle Jensen

Posts: 6
Nickname: palle
Registered: Nov, 2002

Re: Show picture stored in database Posted: Nov 15, 2002 10:55 AM
Reply to this message Reply
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.


yours

Palle Jensen

Flat View: This topic has 2 replies on 1 page
Topic: Help! reading text files!! Previous Topic   Next Topic Topic: writing to a file

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use