aboutsummaryrefslogtreecommitdiff
path: root/src/com.example.portfolio2/com/example/portfolio2/MyDb.java
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-28 16:51:56 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-28 16:51:56 +0200
commite863ece330f9df091c3ec7d9ffee3cd433c4ebee (patch)
tree8fd3d1b2c147b64f3cf1d6782110a0aabd0453c0 /src/com.example.portfolio2/com/example/portfolio2/MyDb.java
parent15b3d0221bd88c4912f536f67b8e00836626bd6f (diff)
use TAP-indentation
Diffstat (limited to 'src/com.example.portfolio2/com/example/portfolio2/MyDb.java')
-rw-r--r--src/com.example.portfolio2/com/example/portfolio2/MyDb.java150
1 files changed, 75 insertions, 75 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/MyDb.java b/src/com.example.portfolio2/com/example/portfolio2/MyDb.java
index f85f391..7796a16 100644
--- a/src/com.example.portfolio2/com/example/portfolio2/MyDb.java
+++ b/src/com.example.portfolio2/com/example/portfolio2/MyDb.java
@@ -4,83 +4,83 @@ import java.sql.*;
import java.util.ArrayList;
class MyDB { // MyDB is all standard Database configuration that was gotten from Mads
- Connection conn = null;
+ Connection conn = null;
- MyDB() {
- if (conn == null) open();
- }
+ MyDB() {
+ if (conn == null) open();
+ }
- public void open() {
- try {
- String url = "jdbc:sqlite:identifier.sqlite";
- conn = DriverManager.getConnection(url);
- } catch (SQLException e) {
- System.out.println("cannot open");
- if (conn != null) close();
- throw new RuntimeException(e);
- }
- ;
- }
+ public void open() {
+ try {
+ String url = "jdbc:sqlite:identifier.sqlite";
+ conn = DriverManager.getConnection(url);
+ } catch (SQLException e) {
+ System.out.println("cannot open");
+ if (conn != null) close();
+ throw new RuntimeException(e);
+ }
+ ;
+ }
- public void close() {
- try {
- if (conn != null) conn.close();
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- conn = null;
- }
- public void cmd(String sql) {
- if (conn == null) open();
- if (conn == null) {
- System.out.println("No connection");
- return;
- }
- Statement stmt = null;
- try {
- stmt = conn.createStatement();
- stmt.executeUpdate(sql);
- } catch (SQLException e) {
- System.out.println("Error in statement " + sql);
- throw new RuntimeException(e);
- }
- try {
- if (stmt != null) {
- stmt.close();
- }
- } catch (SQLException e) {
- System.out.println("Error in statement " + sql);
- throw new RuntimeException(e);
- }
- }
+ public void close() {
+ try {
+ if (conn != null) conn.close();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ conn = null;
+ }
+ public void cmd(String sql) {
+ if (conn == null) open();
+ if (conn == null) {
+ System.out.println("No connection");
+ return;
+ }
+ Statement stmt = null;
+ try {
+ stmt = conn.createStatement();
+ stmt.executeUpdate(sql);
+ } catch (SQLException e) {
+ System.out.println("Error in statement " + sql);
+ throw new RuntimeException(e);
+ }
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (SQLException e) {
+ System.out.println("Error in statement " + sql);
+ throw new RuntimeException(e);
+ }
+ }
- public ArrayList<String> query(String query, String fld) {
- ArrayList<String> res = new ArrayList<>();
- if (conn == null) open();
- if (conn == null) {
- System.out.println("No connection");
- throw new RuntimeException("No connection");
- }
- Statement stmt = null;
- try {
- stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next()) {
- String name = rs.getString(fld);
- res.add(name);
- }
- } catch (SQLException e) {
- System.out.println("Error in statement " + query + " " + fld);
- throw new RuntimeException(e);
- }
- try {
- if (stmt != null) {
- stmt.close();
- }
- } catch (SQLException e) {
- System.out.println("Error in statement " + query + " " + fld);
- throw new RuntimeException(e);
- }
- return res;
- }
+ public ArrayList<String> query(String query, String fld) {
+ ArrayList<String> res = new ArrayList<>();
+ if (conn == null) open();
+ if (conn == null) {
+ System.out.println("No connection");
+ throw new RuntimeException("No connection");
+ }
+ Statement stmt = null;
+ try {
+ stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery(query);
+ while (rs.next()) {
+ String name = rs.getString(fld);
+ res.add(name);
+ }
+ } catch (SQLException e) {
+ System.out.println("Error in statement " + query + " " + fld);
+ throw new RuntimeException(e);
+ }
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (SQLException e) {
+ System.out.println("Error in statement " + query + " " + fld);
+ throw new RuntimeException(e);
+ }
+ return res;
+ }
}