Don Hill
Posts: 70
Nickname: ssswdon
Registered: Jul, 2002
|
|
Re: Retrieving Images from Database
|
Posted: Sep 10, 2002 7:20 AM
|
|
Since what you really are looking for is the bytes why don't you just do a
byte[] bytes = rs.getBytes(n);
FileOutputStream out = new FileOutputStream( fName ); out.write( bytes); out.flush(); out.close()
HTH
> Hello Friend > I am trying to retrieve image from a Database(MS > Access here), but i am not getting desired results. > Many more unwanted bytes are coming along with the > data. > > Sql query of the table is > create table ImageData ( MyImage Memo , Name > varchar(50)) > > The program is > import java.io.*; > import java.sql.*; > > class MultiMediaDatabase > { > public static void main(String args[]) throws > ws Exception > { > > > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); > Connection con = > n con = > DriverManager.getConnection("jdbc:odbc:saddy","",""); > PreparedStatement stmt = > con.prepareStatement("select * from ImageData"); > ResultSet rs= stmt.executeQuery(); > while (rs.next()) > { > InputStream in =rs.getBinaryStream("MyImage"); > String fName = rs.getString("Name"); > System.out.println(fName); > OutputStream out = new > new FileOutputStream(fName); > int i; > while ((i=in.read()) != -1) > { > out.write(i); > } > out.close(); > } // end of while > } // end of main > } > > > > Please help me as i am not able to find out where i > am wrong > > Saddy
|
|