RSS

Category Archives: Database

The Weekly Harvest – الحصاد الأسبوعي-

The Weekly Harvest – الحصاد الأسبوعي-

السلام عليكم ، الحصاد الأسبوعي

The Weekly Harvest 😉

Playing with the User Interface in Android Part-3- by – Marwa AboShall

JDO ” Write once , persist everywhere “ – by – Yomna.M.Hafez

Software Engineering – by – Gamal Azmy

Linux Power User #BeBasata – by – Maggy Hesham

Java Programming : let’s Master (7II) – by – Omar Ezz

 

JDO ”Write Once, Persist Everywhere”

JDO ”Write Once, Persist Everywhere”

JDO “Java Data Objects” :- It’s Java API “application program interface” for transparent persistence, support transactions and multiple users, allows developer to persist Java objects, allows Java developers to use their object model as a data model {There’s no need for developer to spend his time between the data side and Object side}.
JDO allows you to store and retrieve objects in an easy way for Java programmers, instead of working with JDBC or EJB’s persistence, you can work directly with your Java objects.
So that .. you don’t have to copy data to and from database tables or SELECT to perform queries, your JDO implementation perform all processes on persistence and you can make queries based on the fields of your Java objects, using the normal Java syntax.

JDO {unlike JDBC} :
allows multiple users and transactions, So that .. there’s no need to think about SQL and database stuff.
JDO : technology allows you to directly store your Java domain model instances into the persistent store “database”.
JDO : provided by Sun Java Community.
JDO : works with object Databases and Relational Database.
JDO : works also with J2EE “Java Enterprise Edition” and EJB “Enterprise JavaBeans”.

Why we use JDO for Application Programming !?

  1. Database independence :- JDO applications and implementations are independent of the database and support many different types of transactional data stores as : relational and object databases, XML, flat files, …
  2. Easy to use :- JDO programmers can ignore the details of persistence.
  3. Portability :- JDO apps. can run on many platforms and many implementations with no need for re-compiling or change of source code.
  4. JDO Can take all features of EJP “Enterprise JavaBeans” as :-
    • Remote message processing.
    • Automatic distributed transaction .
    • Security.
  5. High performance.

 

JDO Architecture

 ** high-level JDO API :– is designed to provide an interface for JAVA developers to store data, without learning each new data access language “as SQL” for each type of persistent data storage.

 ** low-level JDO API “as JDBC” :- used to store data, it enables JAVA developers to write Java code that accesses the underlying data store, without using specific code for the database.

  • JDO

The main tasks of JDO architecture :-

  1. To provide transparent Java technology for Java application developers.
  2. To enable implementations of data stores into application servers.

Note that :-
JDO doesn’t mean to replace JDBC. They complete each other , each one has unique strengths, and different developers with different skill and different targets can use both.
For example:-

  • ** JDBC offer greater flexibility by giving Java developers direct control over database access.
  • ** JDO offers more facility for developers by hiding SQL, this allows Java developers to focus on the DOM “Document Object Model” without need for knowing or learning SQL.

 

JDO instance :– is a Java class instance that implements the application functions and represents data in an enterprise data store, its class always implement the {Persistence Capable} interface.
As a result, your code becomes easier to maintain, easier to re-use, and easier to test.

  •  The developer doesn’t restricted to‫ ‏‬a specific database, there’s no need for the developer to know whether the data store is a relational database, an object database, or just a set of files.

 

jdo

Finally .. We can briefly present the main goals of JDO :-

  •  —  JDO simplify the transaction implementations of database systems.
  •  — JDO provide a transparent interface from application to database, So that the developer doesn’t have to learn SQL or any other data access language.
  • — JDO make it easy for developers to use the Java model to design the application, and transparently store and retrieve data from different database systems.
  • — JDO make it easy for the developer to connect to different database

 


 

 

 
2 Comments

Posted by on March 11, 2012 in Database, Featured, Programming

 

Tags: ,

SQL and SQLJ

SQL and SQLJ

SQL :-

SQL “Structured Query Language” :- It enables the developer communicate with a database.
SQL statements are used to perform tasks such as :-

  • – create new databases,
  • – create new tables in a database,
  • – access and query database,
  • – retrieve data from database,
  • – insert records in database,
  • – update records in a database,
  • – delete records from a database,
  • – create stored procedures in a database,
  • – create views in a database,
  • – set permissions on tables, procedures, and views.

SQL works with relational databases. A relational database stores data in tables (relations). A database is a collection of tables.
A table consists a list of records. A table is a collection of related data entries and it consists of columns and rows. Each record in a table has the same structure. Each record has a fixed number of “fields” of a given type.

RDBMS “Relational DataBase Management Systems” that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, Ingres.
The data in RDBMS is stored in database objects called tables.

There are 3 basic categories of SQL Statements :-

1- SQL-Data Statements :- query and modify tables and columns.

  • –  SELECT Statement : query tables and views in the database.
  • –  INSERT Statement : add rows to tables.
  • – UPDATE Statement : modify columns in table rows.
  • – DELETE Statement : remove rows from tables.


2- SQL-Transaction Statements
:- control transactions.

  • – COMMIT Statement : commit the current transaction.
  • – ROLLBACK Statement : roll back the current transaction.


3- SQL-Schema Statements
:- maintain schema (catalog).

  • – CREATE TABLE Statement : create tables.
  • – CREATE VIEW Statement : create views.
  • – DROP TABLE Statement : drop tables.
  • – DROP VIEW Statement : drop views.
  • – GRANT Statement : grant privileges on tables and views to other users.
  • – REVOKE Statement : revoke privileges on tables and views from other users.


SQLJ :-

SQLJ :- It’s an easy way for Java programmers to access databases via SQL. Without SQLJ, Java programmers are limited to JDBC result set processing. SQLJ facilitates the development of database oriented projects, during developing Java applications using JDBC, you have to test your SQL against the database. SQLJ enables developers to insert SQL statements directly into the Java code, and the sqlj.exe file convert SQLJ syntax into Java source file. and enables developers to fully control the SQLJ development environment. It enables developers write less code within your Java applications that deal with SQL calls to database.
SQLJ enables SQL statements to be checked during compilation and not runtime. It gives exactly what is needed for quick development, with less code, easy debugging, and automatic performance improvement.

SQLJ programs require fewer lines of code than JDBC programs, hence easier to debug. SQLJ can perform syntactic and semantic checking on the code. using database connections at compile time. SQLJ checks query results and return parameters, while JDBC values are passed to and from SQL without checking at compile time.
SQLJ provides such an efficient way of processing SQL statements, instead o fwriting separate method calls to bind each input parameter and retrieve each select list item, now you can write one SQL statement that uses Java variables, SQLJ takes care of binding.

The SQLJ Standard provide:-
**
The SQLJ Language Specification :
– provides standard language syntax and semantics for ensurance static SQL in Java programs, The SQLJ translator checks the syntax of SQL statements during translation, his check prevents any run-time SQL syntax errors. JDBC doesn’t perform any checks, which allow run-time SQL syntax errors to occur.

** 
The Stored Procedure Specification :
– defines standards for implementing database stored procedures and functions in Java.

** 
The Stored Java Class Specification addresses :-
defines standard ways to store Java datatypes and classes as objects in database.

 

   Differences between SQL and SQLJ :-

  • ** With JDBC, SQL and DML, statements are only validated at runtime and not compile time, AS the SQL is only known as String object to JDBC. SQLJ wont allow invalid SQL to compile and will inform the developer at development time instead of runtime {automatic validation of SQL code}
  • ** SQLJ can execute the same tasks as JDBC with much fewer lines and it’s much easier to read SQL statements line by line in Java.

But Note That :-
With SQLJ .. There’s need for extra step to create compiled code to access the database and it may cause problems !

** You Can learn More from these references .. I think that it’s such an awesome reference and it will be useful :
http://tinman.cs.gsu.edu/~raj/books/Oracle9-chapter-6.pdf
and ..
http://docs.oracle.com/cd/B10501_01/java.920/a96655.pdf
and finally it’s IBM reference ..
http://publib.boulder.ibm.com/infocenter/rtnlhelp/v6r0m0/index.jsp?topic=%2Fcom.ibm.etools.sqlj.doc%2Ftopics%2Fcsqlj.html


 
Leave a comment

Posted by on March 3, 2012 in Database, Featured

 

Hibernate & JDBC

Hibernate & JDBC

Hibernate & JDBC

  •  JDBC “Java Database Connectivity” : It’s the tool by which developers can connect, query and update database using the SQL, developer has to write code to map an object model’s data representation to a relational data model and its database schema, JDBC is Java version of ODBC.
  •  Hibernate : It’s a Flexible ORM soultion for JAVA “Object-Relational Mapping” to map Java classes to database tables, that allows java developers to develop persistent classes by object-oriented using association, inheritance and polymorphism mechanisms, developer does not need to write code explicitly to map database tables tuples to application objects during interaction with RDBMS.


* Note that :
JDBC simples the interaction with RDBMS “Relational database management systems” ,

So that if you want to access database using JAVA application you have to :-

 —  Load the JDBC driver because this driver actually communicates with the database, Then Open connection to database.

Create JDBC Statement object, This object contains SQL query Then execute statement which returns resultset.

 ResultSet : contains the tuples of database table as a result of SQL query.
Then send SQL queries to database using JDBC drivers and work on the returning results from database.

Close the Database connection.

JDBC uses two techniques to communicate with database:

First technique :-

  1.   The JDBC driver connects to database.
  2.   Executes SQL statements.
  3.   Results are sent back from driver to driver manager and finally to the application.
     

Second technique :-

  1.   The JDBC driver communicates with ODBC driver.
  2.   Then ODBC driver executes SQL query
  3.   Then results are sent back to JDBCdriver to driver manager and then to application.ODBC “Data Source” >> JDBC Servlet >> Browser.

Mapping of Java objects with database tables and vice versa conversion is done by the developer “manually” with lines of code.

JDBC supports “only” native Structured Query Language (SQL), Developer has to find out the efficient way to access database, to select query from a number of queries to perform same task.


With JDBC ..
Mapping between Java objects and database tables is done manually.
It is developer’s responsibility to handle JDBC result set and convert it to Java objects through code to use this persistent data in application, So if table changed or database changed then It is developer’s responsibility to change object structure and to change code written to map table-to-object & object-to-table.

Spring’s JDBC framework makes code easy to read and manages connections.

* Note that :

Hibernate is more flexible, powerful and high
performance object relational persistence and query service ,

So that if you want to access Database using Hibernate technique, you will find that :

1. Load the Hibernate configuration file and create configuration object. It will automatically load all mapping files.

Hibernate opens connection to database by itself.

2. Create HQL query “Hibernate Query Language”, Hibernate converts HQL “Hibernate Query Language” statements to database    data   and receives result set – (independent from type of database) that is expressed in SQL like syntax and includes full support for polymorphic queries.

** Hibernate also supports native SQL statements.

Hibernate also selects an effective way to perform a database manipulation task for an application,
Then execute query to get list containing Java objects.

3. Hibernate maps of these database data to Java objects which are directly used by Java application “Automatic Mapping”.


With Hibernate ..
Hibernate provides this mapping “itself“, Actual mapping between tables and application objects is done in XML files, So if there is change in Database or in any table then the need will be to change XML file properties.

  •   Hibernate uses JDBC to connect to the database and execute the dynamic SQL that it generates.
  •   Hibernate is nothing more than a SQL generation engine – it uses bjects and mappings to generate SQL, instead of making writing it by hand.

Now we have these question .. Why Hibernate .. So why not !?

  Why Hibernate :

  1.   Open-Source, Zero-Cost Product License.
  2.   Less code in Hibernate than JDBC.
  3.   Hibernate is standard ORM “Object-Relational Mapping” solution.
  4.   Database Independent.
  5.   Hibernate is layers architecture, So you only use whatyour appllication need.
  6.   Support for Query Language,While JDBC supports only native Structured Query Language “SQL“, Hibernate provides a powerful query language Hibernate Query Language (independent from type of database) and supports native SQL statements.
  7.   Updates and Maintenance, Hibernate reduces lines of code by update object table mapping itself and returns result to the application in Java objects, While is developer’s responsibility to handle JDBC result set and convert it to Java objects and mapping between Java objects and database tables is done manually.

 

  Why not Hibernate :

  1. Debugging and Performance are difficult.
  2. Hibernate is slower than JDBC as it executes lots of SQL statements in runtime.
  3. Internet Support for Hibernate is not powerful.
  4. Hibernate is an overhead for the applications which are simple and use one database that will never change or there are no objects will map between two different tables.
  5. Need to know Hibernate to update application using Hibernat.
 
Leave a comment

Posted by on February 26, 2012 in Database, Featured, Software

 

Tags: , ,

The difference between ODBC and JDBC

The difference between ODBC and JDBC

 What’s the difference between ODBC and JDBC ? let’s see 😉

 

*ODBC


Stands for “Open DataBase Connectivity”: It’s an interface for accessing a databas.
statements enables you to access files in different databases, including Access, DataBase, Excel, and
Text.

*ODBC access the DataBase using SQL requests, ODBC converts these SQL requests into a request that the DataBase can understand.
*
ODBC is a C interface, So that it can’t be used with Java directly, and it’s for Microsoft, used for desktop applications.
*
ODBC requires “manual” installation of the driver manager and driver on client machine.
*
ODBC uses Object Oriented features.

Note That :-
ODBC is used between applications “Just An Interface”.
ODBC Architectur :-
Data Source >> Driver {DBMS} >> ODBC Driver Manger >>Application.

*JDBC

Stands for “Java DataBase Connectivity” : It’s the tool by which developers can connect, query and
update database using the SQL, Including group of Java classes and interfaces, JDBC is built on ODBC, Developer  has to write code to map an object model’s data representation to a relational data model and its database schema.

*
JDBC is Java API “Application programming interfac” used for connecting programs that is written in Java to the data in a relational databass.
*
JDBC Task is to : establish the connection with th DB then send SQL statements to the DB and finally process the result sets “Returned Data”.
*
JDBC allows database application to run on different platforms and interact with different DBMS “DatBase Management Servers”.
*
JDBC is used only for connectivity with java.
*
JDBC is Java version of ODBC.
*
JDBC is an API “Application programming interfac” Specification provided by SUN by which any Java Program can communicate with any database server.
*
With JDBC .. There’s no need for “Manual” installation {Unlike ODBC}, Because JDBC code is written automatically and installed and portable on all platforms.

Note That :-
To access ODBC databases by the JDBC interfaces, you must use a JDBC-ODBC bridge program.
JDBC Architecture :-
DataBase Management System “DBMS” >> ODBC Driver >> JDBC-ODBC bridge >> JDBC Driver Manager >> Java Application.

 
1 Comment

Posted by on February 18, 2012 in Database, Featured

 

Tags: ,