Java Notes Unit-5
Java Notes Unit-5
Page 50
Java2 Platform, Enterprise Edition (J2EE) technology provides a componentbased approach to the design, development, assembly, and deployment of
enterprise applications.
The J2EE platform gives you a multitiered distributed application model, the
ability to reuse components, integrated XML-based data interchange, a unified
security model, and flexible transaction control.
Vendors and customers enjoy the freedom to choose the products and components
that best meet their business and technological requirements.
The JDBC ( Java Database Connectivity) API defines interfaces and classes for
writing database applications in Java by making database connections.
Using JDBC you can send SQL, PL/SQL statements to almost any relational
database. JDBC is a Java API for executing SQL statements and supports basic SQL
functionality.
It provides RDBMS access by allowing you to embed SQL inside Java code.
Page 51
catch( SQLException x ){
System.out.println( Couldnt get connection! );
}
5.3. Creating a JDBC Statement object
x Once a connection is obtained we can interact with the database.
Connection interface defines methods for interacting with the database via the established
connection.
SJBIT, Dept. of ISE
Page 52
x To execute SQL statements, you need to instantiate a Statement object from your connection
object by using the createStatement() method.
x Statement statement = dbConnection.createStatement();
x A statement object is used to send and execute SQL statements to a database.
Prepared Statement: Execute precompiled sql queries with or without parameters. Prep
aredS tatement prepare Statement(String sql)
returns a new PreparedStatement object. Prep aredStatement objects are precompiled SQL
statements.
5.4. Executing a SQL statement with the Statement object, and returning a jdbc resultSet.
x
Statement interface defines methods that are used to interact with database via the
execution of SQL statements.
x
x
For statements that create or modify tables, the method to use is executeUpdate. Note:
Statements that create a table, alter a table, or drop a table are all examples of DDL
statements and are executed with the method executeUpdate. execute() executes an SQL
statement that is written as String object.
ResultSet provides access to a table of data generated by executing a Statement. The table rows
are retrieved in sequence. A ResultSet maintains a cursor pointing to its current row of data.
The next() method is used to successively step through the rows of the tabular results.
ResultSetMetaData Interface holds information on the types and properties of the columns in a
ResultSet. It is constructed from the Connection object.
SJBIT, Dept. of ISE
Page 53