Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.DylanPerez.www;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class CandyCartel {
- private Connection connection;
- private String host, database, username, password;
- private int port;
- public static void main(String[] args) {
- CandyCartel cc = new CandyCartel();
- // host - localhost
- cc.host = "localhost";
- // port - 3306
- cc.port = 3306;
- // database name - candycarteldb
- cc.database = "candycarteldb";
- // username - root
- cc.username = "root";
- // password -
- cc.password = "";
- try {
- cc.openConnection();
- if(!cc.connection.isClosed()) {
- System.out.println("[Candy Cartel] Database has been connected!");
- }
- } catch(SQLException e) {
- e.printStackTrace();
- }
- }
- private void openConnection() throws SQLException {
- if(connection != null && !connection.isClosed()) {
- return;
- }
- connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement