Monday March 27, 2006 Using database in Enterprise application client module. In my last post the new Netbeans project type was presented. Today, I would like to use this project and show how a database connection can be developed in Enterprise application client very simple. Let's start to create application that lists customers that are stored in database.

@Resource(name="jdbc/__default")
private static DataSource ds;
private void readData() {
Connection conn = null;
try{
conn = ds.getConnection();
PreparedStatement pStmt =
conn.prepareStatement("SELECT CUSTOMER_ID, NAME, EMAIL FROM CUSTOMER");
ResultSet rs = pStmt.executeQuery();
while(rs.next()){
custs.add(new Customer(rs.getInt(1), rs.getString(2), rs.getString(3)));
}
}catch(SQLException ex) {
throw new RuntimeException(ex);
}finally {
if(conn != null) {
try {
conn.close();
} catch(SQLException ex) { }
}
}
}
public DisplayCustomerNames() {
initComponents();
cstTableModel = new CustomerTableModel(ds);
jTable1.setModel(cstTableModel);
}

Posted by pprun on March 28, 2006 at 04:22 PM CEST #