Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Make Java DB Your Client-side Portable Database : Page 3

By embedding Java DB in your Java application, you provide a portable database that launches and shuts down as the application does. If that's not enough, you can create XML schemas on the fly using XML files and insert rows into a table without using SQL too.


advertisement

Insert Data into Tables Without SQL

DdlUtils uses the DynaBean class to alter table data. A typical bean has fixed properties and has setter and getter methods for those properties. A DynaBean, as the name indicates, allows dynamic creation of the bean properties. A DynaBean is a Java object that supports properties whose names and data types, as well as values, may be dynamically modified. In this case, the properties are nothing but the column names and column values of the underlying tables.

The following code creates a Java object of table data and inserts it into the table using a platform class:

//insert data into table without SQL insert statement DynaBean userData = database.createDynaBeanFor("userData", false); userData.set("userName", "tiger"); userData.set("password", "singh"); platform.insert(conn, database, userData);



This code technique eliminates the hassle of creating a java.sql.Statement and a java.sql.ResultSet. More importantly, it eliminates having to verify that they are all closed to prevent the application from failing with too many open cursors.

Platform and Database Classes

Among others, the platform and database classes are the important ones in the derby.jar.

The platform interface provides the database-related functionality for processing DML statements such as queries and manipulations. It also contains a SQL builder that is specific to that particular platform. DdlUtils provides separate implementation classes for each database platform. In the sample application, for instance, the platform was "Derby".

The database class represents the database model (i.e., the tables in the database). It also contains the corresponding dyna classes for creating DynaBeans for the objects stored in the tables. A Table class, as the name indicates, represents a Java object for the database table. All DDL statements can be processed using Database and Table classes.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap