if(customer == null){ customer = new Customer(); customer.setId(id); customer.setName(rs.getString("CUSTOMER_NAME")); customer.setAccountNumber(rs.getLong("CUSTOMER_ACCOUNT_NO"));
while (rs.next()) { Customer customer = new Customer(); customer.setId(rs.getInt("id")); ...
public Customer mapRow( ResultSet resultSet, int rowNum ) throws SQLException { Customer c = new Customer (); c.setId( resultSet.getInt( 1 ) ); return c;
public Customer find(Long customerId) throws SQLException { String sql = "SELECT id, name, age FROM customer WHERE id = ?"; Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; Customer customer = null; try { connection = getConnectionSomehow(); preparedStatement = connection.prepareStatement(sql); preparedStatement.setLong(custId); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { customer = new Customer(); customer.setId(resultSet.getLong("id")); customer.setName(resultSet.getString("name")); customer.setAge(resultSet.getInteger("age")); } } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) {} if (preparedStatement != null) try { preparedStatement.close(); } catch (SQLException ignore) {} if (connection != null) try { connection.close(); } catch (SQLException ignore) {} } return customer; }
Customer customer = new Customer(); customer.setId(100); customer.setName("mkyong");
@RequestMapping(value="/customer-list.xml",produces="application/xml") public EntityList<Customer> getCustomerListInXML(){ List<Customer> customerList = new ArrayList<Customer>(); Customer customerObj1 = new Customer(); customerObj1.setId(1); customerObj1.setName("Vijay"); ArrayList<String> favBookList1 = new ArrayList<String>(); favBookList1.add("Book1"); favBookList1.add("Book2"); customerObj1.setFavBookList(favBookList1); customerList.add(customerObj1); Customer customerObj2 = new Customer(); customerObj2.setId(2); customerObj2.setName("Rajesh"); ArrayList<String> favBookList2 = new ArrayList<String>(); favBookList2.add("Book3"); favBookList2.add("Book4"); customerObj2.setFavBookList(favBookList2); customerList.add(customerObj2); EntityList<Customer> listOfCustomers = new EntityList<Customer> (customerList); return listOfCustomers; }
c.setAge(45); c.setDesc("some desc "); c.setId(23); c.setList(list); c.setName("name");
public List<Customer> getCustomerList() { ResultSet queryResponse = null; List<Customer> customerList = new ArrayList<Customer>(); queryResponse = queryDatabase( "SELECT ID01, FIRSTNAME, LASTNAME, CREDITCARD, CID, ADDRESS FROM SCOTT.CUSTOMER_CC"); try { Customer cust = new Customer(); while (queryResponse.next()) { cust.setId(queryResponse.getInt("ID01")); cust.setFirstname(queryResponse.getString("FIRSTNAME")); cust.setLastname(queryResponse.getString("LASTNAME")); cust.setCreditcard(queryResponse.getString("CREDITCARD")); cust.setCid(queryResponse.getString("CID")); cust.setAddress(queryResponse.getString("ADDRESS")); customerList.add(cust); } } catch (SQLException e) { log.warn("Failed to build customer from query response.", e); } assert(!customerList.isEmpty()); return customerList; }
@GET @Produces(MediaType.APPLICATION_XML) @Path("/getCustomer") public Customer getCustomer() { Customer c = new Customer(); c.setName("Fred"); c.setEmail("fred@email.com"); c.setId(12345); return c; }
import javax.jws.*; @WebService public class FindCustomer { @WebMethod public Customer findCustomer(int id) { Customer customer = new Customer(); customer.setId(id); customer.setFirstName("Jane"); customer.setLastName("Doe"); return customer; } }
@Test public void test { Customer cust = new Customer(); cust.setId(1); cust.setName("test"); Address addr = new Address(); addr.setStreet("test-st"); IdCreator c = Mockito.spy(new IdCreator(cust,addr,null)); doReturn(Mockito.mock(UniqueIdCreator.class)).when(c).makeIdCreator(); getDao.getPresist.add(cust); getDao.getPresist.add(addr); c.createId(); }
public Customer getCustomerById(int customerID) { String sql = "SELECT intCustomerID, vachCustomerTitle, vachCustomerFirstName, vachCustomerSurnames, dteCustomerDOB, vachCustomerAddressStreet, vachCustomerAddressTown, vachCustomerAddressCounty, vachCustomerAddressPostalCode, intCustomerHomePhone, intCustomerWorkPhone, intCustomerMobilePhone, vachCustomerEmail FROM h_customers " + "WHERE" + " intCustomerID=?"; try { st.setInt(1, customerID); rs = st.executeQuery(); while (rs.next()){ Customer customer = new Customer(); customer.setId(rs.getInt("intCustomerID")); customer.setTitle(rs.getString("vachCustomerTitle")); customer.setFirstName(rs.getString("vachCustomerFirstName")); //... return customer; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } finally { if(rs != null) { rs.close(); } } }
public static void generateBoo() { try { JAXBContext jc = JAXBContext.newInstance(XmlBoo.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, new MyNamespacePrefixMapper()); XmlBoo xmlBoo = new XmlBoo(); Header header = new Header(); header.setId(101); xmlBoo.setHeader(header); Customer customer = new Customer(); customer.setId(1); customer.setName("Yen"); Address address = new Address(); address.setStreet("Long street"); customer.setAddress(address); xmlBoo.setCustomer(customer); xmlBoo.setSomeBooSpecificField("Specific data in Boo"); m.marshal(xmlBoo, System.out); m.marshal(xmlBoo, new File("xml_boo.xml")); } catch (JAXBException e) { e.printStackTrace(); } }
if (customer == null || customer.getId() != cust_id) { customer = new Customer(); customer.setId(cust_id); customer.setName(rs.getString("cust_name")); customer.setDob(rs.getDate("cust_dob"));
public StreamingOutput get(@Context UriInfo uriInfo, @PathParam("id") int id) { Customer customer = new Customer(); customer.setId(id); customer.setName("Jane Doe");
@Test public void test { Customer cust = new Customer(); cust.setId(1); cust.setName("test"); Address addr = new Address(); addr.setStreet("test-st"); IdCreator c = Mockito.spy(new IdCreator(cust,addr,null) { @Override protected UniqueIdCreator makeIdCreator() { return Mockito.mock(UniqueIdCreator.class); } }); getDao.getPresist.add(cust); getDao.getPresist.add(addr); c.createId(); }
for(CSVRecord record : parser){ Customer emp = new Customer(); emp.setId(record.get("s_id")); emp.setName(record.get("name")); emp.setAge(Integer.parseInt(record.get("age")));
while (rs.next()) { Customer customer = new Customer(); customer.setId(rs.getInt("id")); customer.setName(rs.getString("name")); customer.setAddress(rs.getString("address")); customer.setPhone(rs.getString("phone")); customer.setEmail(rs.getString("email")); customer.setBountPoints(rs.getInt("bonuspoint")); customer.setTotalsale(rs.getInt("totalsale")); customers.add(customer); }
@Test public void updateCustomer_WithValidInput_ShouldReturnUpdatedInput(){ //given final Customer customer = new Customer(); customer.setId("123"); customer.setAddress("Addr1"); customer.setName("Bob"); customer.setCity("St8") customer.setLanguage("Java"); final CustomerInputData inputData = new CustomerInputData(); inputData.setId(customer.getId()); //when when(customerService.getCustomerById(customer.getId())).thenReturn(customer); classUnderTest.updateCustomer(customerData); //then verify(customerService.getCustomerById("123")); assertThat(customerData.getCustomerName(), equalTo(customer.getName())) // and so forth }