Assignment4_1_Server_POJO/src/ws/customer/service/CustomerService.java
public Object[] readAllFromDatabase() {
		List<Customer> customers = new ArrayList<Customer>();
		// Open a connection.
		try (Connection conn = DriverManager.getConnection(CustomerService.url, CustomerService.dbUsername, CustomerService.dbPassword)) {
			// Create preparedStatement obj with specified query.
			String query = "SELECT * FROM " + CustomerService.tableName;
			PreparedStatement getAllCustomer = conn.prepareStatement(query);
			
			// Execute query, get a ResultSet.
			ResultSet retQuery = getAllCustomer.executeQuery();
			
			// Iterate over ResultSet, get all fields (columns) from each row of data.
			while (retQuery.next()) {
				Customer cus = new Customer();
				cus.setCustomerID(retQuery.getInt(1));
				cus.setCustomerName(retQuery.getString(2));
				cus.setShoppingAmount(retQuery.getFloat(3));
				cus.setPrivileged(retQuery.getBoolean(4));
				cus.setDiscountPercentage(retQuery.getInt(5));
				customers.add(cus);
			}
			return customers.toArray();
		} catch (SQLException e) {
			return customers.toArray();
		} 
	}
/**
	 * Get all customers available from the database. 
	 * @return List of Customer obj sent as array of type Object. Be careful that it would return an empty list if exception thrown.
	 */
Get all customers available from the database.
@return List of Customer obj sent as array of type Object. Be careful that it would return an empty list if exception thrown.
Get all customers available from the database . @return List of Customer obj sent as array of type Object . Be careful that it would return an empty list if exception thrown .
public Object[] readAllFromDatabase() {
		List<Customer> customers = new ArrayList<Customer>();
		try (Connection conn = DriverManager.getConnection(CustomerService.url, CustomerService.dbUsername, CustomerService.dbPassword)) {
			String query = "SELECT * FROM " + CustomerService.tableName;
			PreparedStatement getAllCustomer = conn.prepareStatement(query);
			ResultSet retQuery = getAllCustomer.executeQuery();
			while (retQuery.next()) {
				Customer cus = new Customer();
				cus.setCustomerID(retQuery.getInt(1));
				cus.setCustomerName(retQuery.getString(2));
				cus.setShoppingAmount(retQuery.getFloat(3));
				cus.setPrivileged(retQuery.getBoolean(4));
				cus.setDiscountPercentage(retQuery.getInt(5));
				customers.add(cus);
			}
			return customers.toArray();
		} catch (SQLException e) {
			return customers.toArray();
		} 
	}
public Object [ ] readAllFromDatabase ( ) { List < Customer > customers = new ArrayList < Customer > ( ) ; try ( Connection conn = DriverManager . getConnection ( CustomerService . url , CustomerService . dbUsername , CustomerService . dbPassword ) ) { String query = "SELECT * FROM " + CustomerService . tableName ; PreparedStatement getAllCustomer = conn . prepareStatement ( query ) ; ResultSet retQuery = getAllCustomer . executeQuery ( ) ; while ( retQuery . next ( ) ) { Customer cus = new Customer ( ) ; cus . setCustomerID ( retQuery . getInt ( 1 ) ) ; cus . setCustomerName ( retQuery . getString ( 2 ) ) ; cus . setShoppingAmount ( retQuery . getFloat ( 3 ) ) ; cus . setPrivileged ( retQuery . getBoolean ( 4 ) ) ; cus . setDiscountPercentage ( retQuery . getInt ( 5 ) ) ; customers . add ( cus ) ; } return customers . toArray ( ) ; } catch ( SQLException e ) { return customers . toArray ( ) ; } }
Get all customers available from the database.
Get all customers available from the database .
// Open a connection. // Create preparedStatement obj with specified query. // Execute query, get a ResultSet. // Iterate over ResultSet, get all fields (columns) from each row of data.