java.lang.Object
jku.se.DatabaseConnection
Utility class for establishing a connection to the database
and handling file uploads to Supabase bucket storage.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Connection
Establishes a connection to the PostgreSQL database.static String
getPublicFileUrl
(String filePath) Generates a publicly accessible URL for a given file in the Supabase storage bucket.static void
Main method to test the database connection.static String
uploadFileToBucket
(File imageFile) Uploads a file to the Supabase storage bucket.
-
Field Details
-
BUCKET
- See Also:
-
API_KEY
- See Also:
-
URL_SUPABASE
- See Also:
-
-
Constructor Details
-
DatabaseConnection
public DatabaseConnection()
-
-
Method Details
-
getConnection
Establishes a connection to the PostgreSQL database.- Returns:
- A
Connection
object to interact with the database. - Throws:
SQLException
- if the connection fails.
-
uploadFileToBucket
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
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
Main method to test the database connection. Prints a log message if the connection succeeds or fails.- Parameters:
args
- Command line arguments (not used).
-