Module Lunchify
Package jku.se

Class DatabaseConnection

java.lang.Object
jku.se.DatabaseConnection

public class DatabaseConnection extends Object
Utility class for establishing a connection to the database and handling file uploads to Supabase bucket storage.
  • Field Details

  • Constructor Details

    • DatabaseConnection

      public DatabaseConnection()
  • Method Details

    • getConnection

      public static Connection getConnection() throws SQLException
      Establishes a connection to the PostgreSQL database.
      Returns:
      A Connection object to interact with the database.
      Throws:
      SQLException - if the connection fails.
    • uploadFileToBucket

      public static String uploadFileToBucket(File imageFile) throws IOException
      Uploads a file to the Supabase storage bucket.
      Parameters:
      imageFile - The file to upload.
      Returns:
      A public URL pointing to the uploaded file, or null if the upload fails.
      Throws:
      IOException - if an I/O error occurs during upload.
    • getPublicFileUrl

      public static String getPublicFileUrl(String filePath)
      Generates a publicly accessible URL for a given file in the Supabase storage bucket.
      Parameters:
      filePath - The name of the file (including path) in the bucket.
      Returns:
      The full public URL to the file.
    • main

      public static void main(String[] args)
      Main method to test the database connection. Prints a log message if the connection succeeds or fails.
      Parameters:
      args - Command line arguments (not used).