i was wondering if there was some way to write an entire object to an sql db .
not like save all of the info , but ,idk , maybe a serialized version of the object with all of its variables
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.
i was wondering if there was some way to write an entire object to an sql db .
not like save all of the info , but ,idk , maybe a serialized version of the object with all of its variables
Programming: the art that fights back
Yes there is. For my Project we used DatabaseDerby that comes with the NetBeans IDE. First you must connect to the database manually before running the program, then its really easy, its just some repetitive code followed by the statement of what you want to do, like insert, delete etc. Here is a part of my project that did some database executions.
if(addMoneyToAcc == true) //if user pressed "Add Money to Account" button { // This line of code creates an instance of the driver for the database Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); // Connects to the database myConnection = DriverManager.getConnection("jdbc:derby://localhost:1527/BillsDatabase", "root","root"); stmt = myConnection.createStatement(); testQuery="select account_balance from transmitters where transmitter_id=" + transmitterIDNum; //above statement creates an SQL string to be executed results=stmt.executeQuery(testQuery); //executes the query stmt.close(); results.close(); myConnection.close(); // it is important to do all the closing, otherwise u will get an error }
So basically you repeat all the code except the part that is the query, that is what actually alters the database, everything else can be copied and pasted. You have to know how to work with database statements.
You should be able to do this by just serializing the object. But if you want a proper object database I'd recommend you use something like db4o :: Java & .NET Object Database ? Open Source Object Database, Open Source Persistence, Oodb
// Json
Bryan (May 18th, 2010)
I checked db4o out and have read the documentation(well up to chapter 5 or so) and I was amazed! This is truly a beautiful object db. And the "Interface"(db.store() and alike) is also very logical what I really like
A database per file wich can go up to 254GB a file and its fast! Its perfect this way its easier for me to back it up. And i'll be using multiple files ofcourse. Users, shop and those stuff will get their own file
I will have records though, this will be pure data(and alot), not objects so I think I'll still be using PostgreSQL wich I regret. This data will be point calculating(adding or reducing points). But maybe you guys have a better solution?
Last edited by Bryan; May 18th, 2010 at 10:08 AM.