Skip to content

Instantly share code, notes, and snippets.

@boratanrikulu
Last active November 6, 2020 10:40
Show Gist options
  • Save boratanrikulu/75e4a380220f06f5ae4bb112213d82ed to your computer and use it in GitHub Desktop.
Save boratanrikulu/75e4a380220f06f5ae4bb112213d82ed to your computer and use it in GitHub Desktop.
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;
}
}
@boratanrikulu
Copy link
Author

boratanrikulu commented Nov 3, 2020

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