Skip to content
Snippets Groups Projects
Commit c3b51943 authored by Eirik Steira's avatar Eirik Steira
Browse files

Add logging, refactor DBConnection, add javadoc

Remove logger from DBConnection

Remove unused code in DBConnection

Update readme Get Started instructions

Fix typo in docstrings DBConnection
parent a37af0c5
No related branches found
No related tags found
2 merge requests!13Weekly Merge To Master,!10Setup db connection
Pipeline #73416 passed
......@@ -15,6 +15,8 @@
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:mac:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:mac:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:mac:13" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.30" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:13" level="project" />
......@@ -26,6 +28,5 @@
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:13" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -12,7 +12,7 @@
#### IntelliJ:
*Follow these steps to run the project:*
- Open the Maven Projects window in `View -> Tool Windows -> Maven` and click on `ImageApplication -> Plugins -> javafx -> javafx:run` to execute the project
- Open the Maven Projects window in `View -> Tool Windows -> Maven` and click on `ImageApplication -> Plugins -> javafx -> javafx:compile` and then `javafx:run` to execute the project
## Questions or need help
*Link to [our wiki](https://gitlab.stud.idi.ntnu.no/eirsteir/team-14-software-engineering/-/wikis/home) page, maybe add contact info*
......
......@@ -10,6 +10,11 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
......
package NTNU.IDATT1002;
import NTNU.IDATT1002.database.Database;
import NTNU.IDATT1002.database.DBConnection;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
......@@ -8,22 +8,16 @@ import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
public class App extends Application {
private static Scene scene;
@Override
public void start(Stage stage) throws IOException, SQLException {
public void start(Stage stage) throws IOException {
scene = new Scene(loadFXML("login"));
stage.setScene(scene);
stage.show();
Connection connection = Database.getConnection();
System.out.println(connection.isValid(1000));
}
static void setRoot(String fxml) throws IOException {
......
......@@ -5,33 +5,29 @@ import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Logger;
/**
* TODO:
* java.sql.SQLException: Access denied for user 'eirsteir_root'@'dhcp-10-22-12-209.wlan.ntnu.no' (using password: YES)
*/
public class Database {
* Class for connecting to the database. This will load configurations and create a connection pool.
*/
public class DBConnection {
private static final Logger logger = Logger.getLogger(Database.class.getName());
private static HikariConfig config;
private static HikariDataSource dataSource;
/**
* Load configuration and setup the data source
*/
static{
config = new HikariConfig("datasource.properties" );;
HikariConfig config = new HikariConfig("datasource.properties" );
dataSource = new HikariDataSource(config);
}
/**
* Gets a connection from the HikariCP connection pool
* Establish a connection pool to the database
*
* @return Connection to the database
* @throws SQLException
*/
public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment