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
Printable View
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
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.
Code :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
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 :D
A database per file wich can go up to 254GB a file and its fast! Its perfect :D 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 :D
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?