Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v5.2
 
  Buy Now
  Support
  Download
  Document
  FAQ
  HXTT Cobol v2.1
  HXTT DBF v5.2
  HXTT Excel v4.2
  HXTT Paradox v5.2
  HXTT Text(CSV) v5.2
  HXTT XML v1.2
Offshore Outsourcing
Oracle Data Import/Export
DB2 Data Import/Export
Sybase Data Import/Export
Free Resources
  Firewall Tunneling
  Search Indexing Robot
  Conditional Compilation
  Password Recovery for MS Access
  Password Recovery for Corel Paradox
  Checksum Tool for MD5
  Character Set Converter
  Pyramid - Poker of ZYH
   
   
   
Hongxin Technology & Trade Ltd. of Xiangtan City (abbr, HXTT)

HXTT ACCESS
OLE Objects as images with greater size are not readable
AEL
2013-12-24 03:55:39.0
Hello,

I insert images into access database table in an OLE object field. What I'm not able to do is read them back and show them in my GUI (size > 60 Kb). what I have noticed is that the binary representation of two different images with different size is the same and doesn't seems to be an image content at all.
My question is how can I store them and get them back correctly ?

Thanks.
Re:OLE Objects as images with greater size are not readable
HXTT Support
2013-12-24 05:47:13.0
Pasted test with a file with 199,055 byte.
Please email support At hxtt.com your sample. The simple test code is pasted following:

package test.jdbc.access;

import java.io.*;
import java.sql.*;
import java.util.Properties;

public class testOLEPicture1 {

public static void main(String argv[]) {
try {
Class.forName("com.hxtt.sql.access.AccessDriver");
String jdbcConnection = "jdbc:access:////test/access/issue/testhxtt.mdb";
Connection con = DriverManager.getConnection(jdbcConnection);

{
//init db
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("create table if not exists hxtttest (fileno int,img LONGVARBINARY)");
}

int fileNo=1;
String srcfilePath="c:/temp/sample.png";
String dstfilePath="c:/temp/sampleout.png";
{
//Insert an image file
PreparedStatement stmt = con.prepareStatement(
"insert into hxtttest (fileno,img) values(?,?);",
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt.setInt(1,fileNo);
FileInputStream fin = new FileInputStream(srcfilePath);
stmt.setBinaryStream(2,fin);
stmt.executeUpdate();
stmt.close();
fin.close();
}

PreparedStatement stmt = con.prepareStatement(
"select * from hxtttest where fileno="+fileNo,
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery();
rs.next();
Blob photo = rs.getBlob("img");
InputStream in = photo.getBinaryStream();

FileOutputStream fout = new FileOutputStream(dstfilePath);
int b;
int count = 0;
while((b = in.read())!=-1){
count++;
fout.write(b);
}

fout.close();

rs.close();
stmt.close();
con.close();

System.out.println("Writed byte:"+count);

} catch (SQLException sqle) {
do {
System.out.println(sqle.getMessage());
System.out.println("Error Code:" + sqle.getErrorCode());
System.out.println("SQL State:" + sqle.getSQLState());
sqle.printStackTrace();
} while ((sqle = sqle.getNextException()) != null);
} catch (Exception e) {
// System.out.println(e.getMessage());
System.out.println(e.toString());
// e.printStackTrace();
}
}
}

Re:Re:OLE Objects as images with greater size are not readable
ygu
2013-12-24 08:01:14.0
Sample app sent to support
Re:Re:Re:OLE Objects as images with greater size are not readable
HXTT Support
2013-12-25 03:37:47.0
Whether your upload servlet is cracking your data? According to my simple test for your hibernate bean, no issue to read/write local file.


package test.jdbc.hibernate;

import java.io.*;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;


public class testAccessOLE2 {


public static void writeImage(EntityManager em,String srcfilePath) throws Throwable {

Portrait portrait = new Portrait();
File file=new File(srcfilePath);
FileInputStream fin = new FileInputStream(srcfilePath);
byte[] content=new byte[(int)file.length()];
fin.read(content);
fin.close();

portrait.setPortrait(content);
final String[] tokens = file.getName().split("\\.");
portrait.setImageFormat(tokens[tokens.length - 1]);
User user = em.getReference(User.class, 10L);
portrait.setUser(user);
em.getTransaction().begin();
em.persist(portrait);
em.getTransaction().commit();
}

public static void readImage(EntityManager em,String outDirPath) throws Throwable {
Query query = null;
query = em.createQuery("from test.jdbc.hibernate.Portrait");
List portraits = query.getResultList();
for(int i=0;i Portrait portrait=(Portrait)portraits.get(i);
FileOutputStream fout = new FileOutputStream(outDirPath+"\\"+portrait.getId()+"."+portrait.getImageFormat());
fout.write(portrait.getPortrait());
fout.close();
}
System.out.println("Output "+ portraits.size()+" image fles.");
}


public static void main(String[] args) throws Throwable {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("testAccessOLE");
EntityManager em = emf.createEntityManager();


// writeImage(em,"c:/temp/Portrait.PNG");
// writeImage(em,"c:/temp/sample.png");


readImage(em,"c:/temp/output");

em.close();


}


}
Re:Re:Re:OLE Objects as images with greater size are not readable
HXTT Support
2013-12-25 04:44:10.0
I have tested your sample, and that issue should be in our engine for blobl object cache.
Re:Re:Re:Re:Re:OLE Objects as images with greater size are not readable
HXTT Support
2013-12-25 07:14:23.0
Fixed.
Re:Re:Re:Re:Re:Re:OLE Objects as images with greater size are not readable
ygu
2013-12-25 08:50:35.0
Thanks

Search Key   Search by Last 50 Questions




Google
 

Address: 9 Station Rd., Xiangtan City, Hunan Province, P.R. China
Postcode: 411100
Phone: (86)731-58225727
Fax: (86)731-58225727
Email: webmaster@hxtt.com
Copyright © 1999-2011 Hongxin Technology & Trade Ltd. | All Rights Reserved. | Privacy | Legal | Sitemap