Creating Applications Using Advanced Features of JDBC
Creating Applications Using Advanced Features of JDBC
PreparedStatement Object
Consider a scenario where New Publishers, a
publishing house, maintains details about books
and authors in a database. The management of
New Publishers wants an application that can help
them access the details about authors based on
different criteria.
For example,
stat.setString(1,"A001");
ResultSet result=stat.executeQuery();
stat.setString(1,aid.getText());
ResultSet result=stat.executeQuery();
while(rs.next())
{
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
PreparedStatement ps = con.prepareStatement(str);
ps.setString(1, "1001");
ps.setString(2, "Abraham White");
int rt=ps.executeUpdate();
PreparedStatement ps = con.prepareStatement(str);
ps.setString(1, "CA");
ps.setString(2, "Oakland");
int rt=ps.executeUpdate();
PreparedStatement ps = con.prepareStatement(str);
ps.setString(1, "Abraham White");
int rt=ps.executeUpdate();
Activity: Creating an Application that
Uses the PreparedStatement Object
Problem Statement
The management of City library has decided to
computerize the book inventory. The library
management has assigned the preceding task to
a leading software development company of the
US.
The Lead Analyst has assigned the development
of the Book Inventory application to Mark, the
Senior Software Developer.
For example,
a JDBC application is used to transfer money from
one bank account to another. This transaction
gets completed when the money is deducted from
the first account and added to the second.
con.rollback();
In the preceding code snippet, con represents a
Connection object.
Live Demo
Implementing Batch Updates in JDBC
con.setAutoCommit(false);
Statement stmt=con.createStatement();
int[] updcount=stmt.executeBatch();