Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package astatine.login.database;
- import java.io.File;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Database {
- private Connection connection;
- private File file;
- private Statement stmt;
- public Database(File f) {
- this.file = f;
- try {
- Class.forName("org.sqlite.JDBC");
- this.connection = DriverManager.getConnection("jdbc:sqlite:" + file);
- this.stmt = this.connection.createStatement();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private Database(String urlconn) {
- try {
- this.connection = DriverManager.getConnection(urlconn);
- this.stmt = this.connection.createStatement();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public Database(String host, String database, String pass) {
- this("jdbc:mysql://" + host + "/" + database + "?" + "user=astatibr2@177.101.144.170&password=" + pass);
- }
- public Connection getConnection() {
- return this.connection;
- }
- public void update(String sql){
- try {
- this.stmt.executeUpdate(sql);
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("Erro ao Executar SQL");
- }
- }
- public void update(PreparedStatement sql){
- try {
- sql.executeUpdate();
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("Erro ao Executar SQL");
- }
- }
- public PreparedStatement prepareStatement(String sql){
- try {
- return this.connection.prepareStatement(sql);
- } catch (SQLException e) {
- System.out.print("SQLException: " + e.getCause());
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement