diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-29 08:09:28 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-29 08:09:28 +0200 |
commit | 3738c1fc8b2fa92b819b1ff948b3b39de60757b7 (patch) | |
tree | c5db7a878770da6c8180cc468184712d585b0d88 /src/com.example.portfolio2 | |
parent | 794be4694f1a1fa36d87543aab840331c6d39745 (diff) |
always use brace in for- and if-construct
Diffstat (limited to 'src/com.example.portfolio2')
-rw-r--r-- | src/com.example.portfolio2/com/example/portfolio2/Database.java | 9 | ||||
-rw-r--r-- | src/com.example.portfolio2/com/example/portfolio2/MyDB.java | 20 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Database.java b/src/com.example.portfolio2/com/example/portfolio2/Database.java index a4a9271..a6a144a 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/Database.java +++ b/src/com.example.portfolio2/com/example/portfolio2/Database.java @@ -29,8 +29,9 @@ class Database { /// @param name activity name /// @return index of activity as integer int getActivityIndeks(final String name) { - if (name == null) + if (name == null) { return -1; + } ArrayList<String> result = db.query("select indeks from activity a where name is '" + name + "';", "indeks"); return Integer.parseInt(result.getFirst()); @@ -69,11 +70,13 @@ class Database { /// @param program programme name /// @return ECTS points as String String getSumEcts(final String program) { - if (program == null) + if (program == null) { return "0"; + } ArrayList<String> result = db.query("select sum(activity.ects) as total_ects,student.name from student left outer join participation on student.studid = participation.studid inner join activity on participation.indeks = activity.indeks where program is '" + program + "' group by student.studid ;", "total_ects"); - if (result.isEmpty()) + if (result.isEmpty()) { return "0"; + } return result.getFirst(); } diff --git a/src/com.example.portfolio2/com/example/portfolio2/MyDB.java b/src/com.example.portfolio2/com/example/portfolio2/MyDB.java index 9b02d39..ea0f6d6 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/MyDB.java +++ b/src/com.example.portfolio2/com/example/portfolio2/MyDB.java @@ -15,7 +15,9 @@ public class MyDB { /// foo MyDB() { - if (conn == null) open(); + if (conn == null) { + open(); + } } /// foo @@ -25,7 +27,9 @@ public class MyDB { conn = DriverManager.getConnection(url); } catch (SQLException e) { System.out.println("cannot open"); - if (conn != null) close(); + if (conn != null) { + close(); + } throw new RuntimeException(e); } ; @@ -34,7 +38,9 @@ public class MyDB { /// foo public void close() { try { - if (conn != null) conn.close(); + if (conn != null) { + conn.close(); + } } catch (SQLException e) { throw new RuntimeException(e); } @@ -44,7 +50,9 @@ public class MyDB { /// foo /// @param sql foo public void cmd(final String sql) { - if (conn == null) open(); + if (conn == null) { + open(); + } if (conn == null) { System.out.println("No connection"); return; @@ -73,7 +81,9 @@ public class MyDB { /// @return foo public ArrayList<String> query(final String query, final String fld) { ArrayList<String> res = new ArrayList<>(); - if (conn == null) open(); + if (conn == null) { + open(); + } if (conn == null) { System.out.println("No connection"); throw new RuntimeException("No connection"); |