Last active
November 6, 2020 10:40
-
-
Save boratanrikulu/75e4a380220f06f5ae4bb112213d82ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package databaseProcesses; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
public class DatabaseConnector { | |
public Connection connection = null; | |
/* constructor */ | |
public DatabaseConnector() { | |
String url = "jdbc:mysql://localhost:3306/databaseAdim?useUnicode=true&characterEncoding=utf8"; | |
try { // loads driver | |
Class.forName("org.mariadb.jdbc.Driver"); | |
System.out.println("Driver is loaded."); | |
} catch (ClassNotFoundException ex) { | |
System.out.println("Driver is not found."); | |
} | |
try { // makes connection | |
connection = DriverManager.getConnection(url, "root", "password"); | |
System.out.println("Connection is successful."); | |
} catch (SQLException ex) { | |
System.out.println("Connection is failed."); | |
} | |
} | |
/* getter */ | |
public Connection getConnection() { | |
return this.connection; | |
} | |
} |
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: