A heckin ton. Mostly hackish
This commit is contained in:
parent
052052d76b
commit
b229ff9a15
70 changed files with 2226 additions and 881 deletions
56
backend/src/main/java/achievements/misc/DbConnection.java
Normal file
56
backend/src/main/java/achievements/misc/DbConnection.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package achievements.misc;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
|
||||
|
||||
@Component
|
||||
public class DbConnection {
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@Value("${database.server}")
|
||||
private String serverName;
|
||||
@Value("${database.name}")
|
||||
private String databaseName;
|
||||
@Value("${database.user.name}")
|
||||
private String username;
|
||||
@Value("${database.user.password}")
|
||||
private String password;
|
||||
|
||||
public DbConnection() {}
|
||||
|
||||
@PostConstruct
|
||||
public void connect() {
|
||||
try {
|
||||
var dataSource = new SQLServerDataSource();
|
||||
dataSource.setServerName (serverName );
|
||||
dataSource.setDatabaseName(databaseName);
|
||||
dataSource.setUser (username );
|
||||
dataSource.setPassword (password );
|
||||
connection = dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void disconnect() {
|
||||
try {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue