Results 1 to 11 of 11
  1. #1
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default regarding saving files or objects in database

    hi to all,
    I need a suggestion from regarding saving object or any kind of file either it is a object or simple file or word document or image etc.. to a sql database.What is the efficient way to store such kind of objects to save in database.
    I know only two kinds of saving objects.
    1)Using Blob and saving object directly in data base.
    2)Using serialization to serialize objects or files and store in database and retrieve using externalization.
    Most important thing is effect way of storing data and retrieve data in same original format.
    Which one of this is good and are they any more effective ways for my requirement
    Thanks to all in advance

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Both those methods will be held in the db as a BLOB, since they are both binary data.
    The db doesn't care exactly what the data is, it just cares that it is binary.

  3. #3
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    thank u , I know it but what i need is efficient way to store objects or files in database.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    But they both do the same thing.
    Take an InputStream and pass it into the setBinaryStream() method of the PreparedStatement.

    Why do you think they're different in any way?

  5. #5
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    I think i didn't ask the my question clearly. What I need is there any other way to store object except those two ,so that it is more efficient and which is very popular in usage.
    Actually i know only those two kinds of saving objects.I want two know about any other ways[if they are available], to store data that more popular in usage?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Oh right.

    Well, serialising is not the normal method of storing an object...normally (and this is my field really) you would create a table structure that represented your data model (ie your classes) and interact with that. Often using something like Hibernate, though you can code it yourself (which is good practice if you need to learn SQL and want to know what Hibernate is essentially doing under the hood).

  7. #7
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    Is that means mapping my objects with the table(i.e that means mapping my classes fields using hibernate configuration file with table structure) will do the all the essential work what i need?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Pretty much.
    It's what Hibernate was written for, and it means you can query the data held in the database, which you couldn't do if it was all BLOBs.

  9. #9
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    I have small doubt with hibernate ,if my table contain a column name like for example "name_1" . I am trying to map this column in hibernate configuration file(cfg.xml) with same name like
    "name_1" .In this case i am getting error if i am using that column some where in my code it is giving error like column not find. Why it so?
    Last edited by sandeepsai39; 08-27-2010 at 09:52 AM.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    No idea.
    Post the full exception, and possibly your mappings (not that I can ever remember how to do the mappings).

  11. #11
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    sorry ,for last question i didn't check it properly ,it is working fine.

    Is it possible to create database connections in hibernate.cfg.xml. For example like below

    Java Code:
    <session-factory>
    		<property name="dialect">
    			org.hibernate.dialect.MySQLDialect
    		</property>
    		<property name="connection.url">
    			jdbc:mysql://localhost:3306/test
    		</property>
    		<property name="connection.username">root</property>
    		<property name="connection.password">root</property>
    		<property name="connection.driver_class">
    			com.mysql.jdbc.Driver
    		</property>
    		<property name="myeclipse.connection.profile">
    			com.mysql.jdbc.Driver
    		</property>
    	<mapping resource="com/hibernateDemo/Tbltest.hbm.xml"  />
    
    	</session-factory>
           <session-factory>
    		<property name="dialect">
    			org.hibernate.dialect.MySQLDialect
    		</property>
    		<property name="connection.url">
    			jdbc:mysql://localhost:3306/test
    		</property>
    		<property name="connection.username">root</property>
    		<property name="connection.password">root</property>
    		<property name="connection.driver_class">
    			com.mysql.jdbc.Driver
    		</property>
    		<property name="myeclipse.connection.profile">
    			com.mysql.jdbc.Driver
    		</property>
    	<mapping resource="com/hibernateDemo/Tbltest.hbm.xml"  />
    
    	</session-factory>
           <session-factory>
             ///another database definitions[like say remote databse]
          </session-factory>
           </session-factory>

Similar Threads

  1. Saving Objects Permanently?
    By ethann_91 in forum New To Java
    Replies: 1
    Last Post: 01-20-2010, 08:03 AM
  2. Exception while saving in database
    By kirtichopra2003 in forum Web Frameworks
    Replies: 1
    Last Post: 10-24-2009, 02:15 AM
  3. help needed in saving objects
    By sandeepsai17 in forum New To Java
    Replies: 6
    Last Post: 06-30-2009, 04:02 AM
  4. saving date and time in a derby database from an ejb module
    By Dave in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-22-2008, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •