StAX - reading base64 string from xml into db

二次信任 提交于 2019-12-06 07:42:04

How often are you flushing out your entities?

I think you're building too many entities and not flushing your session frequently enough which results in all those objects being created to be kept in the current session.

May want to check that.

Edit

The comments below indicated that the submitter wanted a way to insert binary blob data directly in to the database.

Instead of doing this with hibernate, this can be achieved with just JDBC.

java.sql.Connection conn = ...
java.sql.PreparedStatement pstmt= conn.prepareStatement("insert into ENTITY_TABLE (BASE64) VALUES (?)");
InputStream is= ... // byte data
pstmt.setBinaryStream(1, is);
int numUpdated= pstmt.executeUpdate();

Now be advised, this is REAL rough and tumble. This is making the assumption that the ENTITY_TABLE is using a database generated identifier for the row and that columns other than BASE64 are allowed to have nulls or have reasonable defaults. The executeUpdate will run the insert statement taking the value of is as the value of the blob data.

I hope this gets you closer to your solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!