Java Reference
In-Depth Information
}
The following code is an excerpt from DBUtils.java . It shows the
saveRssFeed() method responsible for persisting RSS feeds:
public static int saveRssFeed(RssFeed rssFeed) {
int pk = rssFeed.link.hashCode();
loadDriver();
Connection conn = null;
ArrayList statements = new ArrayList();
PreparedStatement psInsert = null;
Statement s = null;
ResultSet rs = null;
try {
// database name
String dbName = "demoDB";
conn = DriverManager.getConnection(protocol
+ dbName
+ ";create=true", props);
rs
= conn.createStatement().executeQuery("select count(id)
from rssFeed where id = "
+
rssFeed.link.hashCode());
rs.next();
int count = rs.getInt(1);
if (count == 0) {
// handle transaction
conn.setAutoCommit(false);
Search WWH ::




Custom Search