Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrwilbroad/introduction-to-java
Introduction to Java programming Language
https://github.com/mrwilbroad/introduction-to-java
Last synced: about 2 months ago
JSON representation
Introduction to Java programming Language
- Host: GitHub
- URL: https://github.com/mrwilbroad/introduction-to-java
- Owner: mrwilbroad
- Created: 2024-09-06T04:53:16.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-09T14:24:43.000Z (3 months ago)
- Last Synced: 2024-09-09T17:23:28.978Z (3 months ago)
- Language: Java
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
- CONNECT JAVA WITH POSTGRESQL DATABASE
1. Retrieve data
2. Save data
- ALL operation through PreparedStatement
```java
public List all()
{
String Sql = "SELECT * FROM employee;";
List staffs = new ArrayList<>();try(
Connection connection = this.connection();
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(Sql);
){while (result.next()){
Staff staff = new Staff();staff.id = result.getInt("id");
staff.first_name = result.getString("first_name");
staff.last_name = result.getString("last_name");
staff.email = result.getString("email");
staff.gender = Gender.valueOf(result.getString("gender"));
staff.age = result.getInt("age");
staff.salary = result.getDouble("salary");
staff.region = result.getString("region");
staff.department = result.getString("department");
staffs.add(staff);
}}catch (SQLException e){
this.Close();
throw new RuntimeException(e);}
return staffs;
}
```- Good way to use Stream to handle data in multiple way
```java
public void showStaffs (){
Staff staff = new Staff();List staffs = staff.all();
// all staffs
staffs.forEach(staf -> System.out.printf("%s%n%n",staf.getStaffInfo()));List FilteredStaff = staffs.stream()
.filter(thisStaff -> thisStaff.getAge() < 40)
.toList();// staffs with age below 40
FilteredStaff.forEach(staf -> System.out.printf("%s%n%n",staf.getStaffInfo()));}
```