Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: what data type should i use in MySql for a java object to be saved

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default what data type should i use in MySql for a java object to be saved

    i really dont know how to ask this properly. but what database data type should i use if im going to save a java object

    consider this Person class
    public class Person  implements java.io.Serializable {
     
        private String fName;
        private String mName;
        private String lName;
        private int age;
     
        public Person(String f, String m, String l, int age) {
     
            fName = f;
            mName = m;
            lName = l;
            this.age = age;
        }
     
        public String getFName() {
     
            return fName;
        }
     
        public String getMName() {
     
            return mName;
        }
     
        public String getLName() {
     
            return lName;
        }
     
        public int getAge() {
     
            return age;
        }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: what data type should i use in MySql for a java object to be saved

    I'd recommend not saving the object in the first place...save the data within the object and provide functions which map said between the object and the database with getters and setters - this takes advantage of the real use of a relational database (key word relational). That being said, you could use a BLOB.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    36
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: what data type should i use in MySql for a java object to be saved

    As I know, there is no data type in mysql for object, but you can create a special table for the object. e.g., you can create a table of person for the person object.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: what data type should i use in MySql for a java object to be saved

    Quote Originally Posted by luck999 View Post
    As I know, there is no data type in mysql for object, but you can create a special table for the object. e.g., you can create a table of person for the person object.
    Yes there is...its called a BLOB (but see my post above) It can hold anything from images, to java objects, to text, to whatever. Through JDBC you can read/write to the blob using an Input/OutputStream

  5. The Following User Says Thank You to copeg For This Useful Post:

    chronoz13 (October 9th, 2011)

  6. #5
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: what data type should i use in MySql for a java object to be saved

    thank you for all the responses, yes i found out that BLOB type is the type that MySql can handle regarding with java objects

Similar Threads

  1. Primitive data type
    By stuart harper in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 17th, 2011, 12:14 PM
  2. How to perform operations on arguments with type OBJECT?
    By hexwind in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 3rd, 2011, 12:17 PM
  3. [SOLVED] i cant make a java jar file which can search data from mysql
    By talha07 in forum JDBC & Databases
    Replies: 6
    Last Post: January 20th, 2011, 05:09 AM
  4. saving list of data from JSP into java object
    By nrao in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: January 12th, 2011, 10:24 AM
  5. About heap data type
    By PaddyWangTheGG in forum Algorithms & Recursion
    Replies: 2
    Last Post: May 17th, 2010, 03:02 PM