Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package best.ranked.sql;
- import java.sql.*;
- public class ManagerConnection {
- public static Connection connection;
- public static Statement stmt;
- public ManagerConnection(String urlconn, String user, String password) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection(urlconn, user, password);
- stmt = connection.createStatement();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public ManagerConnection(String host, String database, String user, String pass) {
- this("jdbc:mysql://" + host + "/" + database, user, pass);
- }
- public static Connection getConnection() {
- return connection;
- }
- public static void update(String sql) {
- try {
- stmt.executeUpdate(sql);
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("Erro ao Executar SQL");
- }
- }
- public static 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 connection.prepareStatement(sql);
- } catch (SQLException e) {
- System.out.print("SQLException: " + e.getCause());
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment