Take the 2-minute tour ×

I'm doing a tutorial roseindia.net (http://www.roseindia.net/tutorial/java/jdbc/dataaccessobjectdesignpattern.html) and to make the bean StudentBean.java implement java.io.Serializable interface.

Does this have any reason? Is the data stored differently in the database to implement Serializable interface?

share|improve this question
check this stackoverflow.com/questions/2020904/… –  NPKR Sep 28 '12 at 4:58
You are doing a tutorial from perhaps the most notorious site of programming misinformation on the Internet. Please try to find a better one. –  EJP Sep 28 '12 at 7:18

2 Answers 2

The tutorial you linked to does not make use of the class being Serializable.

They might have thrown it in there to follow a general Java bean pattern, but it is not needed for writing it to a database via JDBC. You are rightly confused about this, because there is no explanation.

Serializable is used for ObjectOutputStream, for example to write to files or transfer the bean over the network using RMI. So for a data transport object, this is not a bad feature to support.

share|improve this answer
I understand, excellent response, very successful for me. I just have one more question: I could store the state of my object in the DB as a set of bits implementing serializable interface? I say this in case you want to store an object with attributes more complex than simple strings or integers (such as a map or an arraylist) –  felipecamposclarke Sep 28 '12 at 7:16
Yes, you could turn a Serializable object into a byte[] (binary data) and then put that it the DB. But then it cannot be queried in SQL anymore (because the database has no idea what those bytes mean). –  Thilo Sep 28 '12 at 7:21
Thanks, your answer helped me a lot –  felipecamposclarke Sep 28 '12 at 7:27

Java provides classes to support writing object state to streams and restoring objects from streams. java.io.Serializable is an Marker Interface which provides ability to selialize the object's state of your class(which implements Serializable) in DB table,Files or to transfer over network etc.

share|improve this answer
No, it's not. JDBC setString/setInt is used to store the object state. –  Thilo Sep 28 '12 at 5:32
I understand that it is possible to save the state of an object through seriazisable interface (through the transformation of this a set of bits), but in the link you put above, the attributes of the class to persist are stored in the database like any other data (could have done the same thing without the serializable interface) am I right? –  felipecamposclarke Sep 28 '12 at 7:13

Your Answer


