I have Customer class that make connection to db and save data to mysql. I use tomcat7 and mysql. I want to test this class. I have this method:
public CustomerData findById(int customerId) throws SQLException {
Connection conn = null;
PreparedStatement stmt = null;
CustomerData customer = null;
try {
String sql = "SELECT id, status, username, email, age, country, city, is_hidden FROM "
+ TABLE + " WHERE id = ?";
conn = DBManager.getConnection();
stmt = conn.prepareStatement(sql);
stmt.setInt(1, customerId);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
customer = new CustomerData(rs.getInt(1), rs.getInt(2),
rs.getString(3), null, rs.getString(4), rs.getInt(5),
String.valueOf(rs.getInt(6)), String.valueOf(rs
.getInt(7)), 0, rs.getInt(8));
}
return customer;
} finally {
closeConnection(conn, stmt);
}
}
How can I test it?