Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import com.teamincredibles.settings.Settings;
- public class Database {
- private Connection connection;
- public void connect() {
- try {
- Class.forName(Settings.getDatabaseDriver());
- connection = DriverManager.getConnection(Settings.getJdbcUrl(), Settings.getDBUserName(), Settings.getDBPassword());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public boolean prepareStatement(String query, String choice1) {
- boolean flag = false;
- try {
- PreparedStatement ps = connection.prepareStatement(query);
- ps.setString(1, choice1);
- ResultSet rs = ps.executeQuery();
- flag = rs.next();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return flag;
- }
- public boolean prepareStatement(String query, String choice1, String choice2) {
- boolean flag = false;
- try {
- PreparedStatement ps = connection.prepareStatement(query);
- ps.setString(1, choice1);
- ps.setString(2, choice2);
- ResultSet rs = ps.executeQuery();
- flag = rs.next();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return flag;
- }
- public void executeUpdate(String query) {
- try {
- Statement statement = connection.createStatement();
- statement.executeUpdate(query);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public boolean execute(String query) {
- boolean result = false;
- try {
- Statement statement = connection.createStatement();
- result = statement.execute(query);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return result;
- }
- public ResultSet executeQuery(String query) {
- ResultSet result = null;
- try {
- Statement statement = connection.createStatement();
- result = statement.executeQuery(query);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return result;
- }
- public void disconnect() {
- try {
- if (connection != null) {
- connection.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement