A heckin ton. Mostly hackish

This commit is contained in:
Gnarwhal 2021-02-16 14:11:12 -05:00
parent 052052d76b
commit b229ff9a15
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
70 changed files with 2226 additions and 881 deletions

View 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();
}
}
}