1

I want to insert and retrieve a a user defined Object in DB,am using Mysql5.1. 1)What should me the data type for the column(is Blob is the correct answer for this question)

I am using EntityClass to Insert/Get values from the DB. 2)but to how to insert Object in database?

1
  • i am not sure if i understand the question correctly but i believe you can serialize your objects and store in the DB like you would store in flat file. Commented Oct 26, 2009 at 7:25

1 Answer 1

1

The common way is to translate the object to a table - every field of the object is (toughly) translates to a column of the table. The term for this is object relational mapping. There is plenty of documentation of this on the web (like this) as this is one of the cornerstones of modern day enterprise development.

There are several libraries you can use, and the best is to stick to the standard called JPA - Java Persistence API. The most known libraries (all open source) are

Your user defined object will look like this :

@Entity
@Table(name = "some_table")
public class SomeObject implements Serializable {

    static final long serialVersionUID = <some value>;

    @Id
    @GeneratedValue
    protected Long id;

    @Column
    protected String name;

    @Column
    protected int value;

    // default constructor
    // getters, setters
    // equals, hashCode, toString
    // other methods
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.