Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.Driver;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class Main
- {
- private static String URL =
- "jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC";
- private static String USERNAME = "Admin";
- private static String PASSWORD = "1260035";
- public static void main(String[] args)
- {
- Connection connection = null;
- Driver driver;
- try
- {
- driver = new com.mysql.cj.jdbc.Driver();
- DriverManager.registerDriver(driver);
- }
- catch(SQLException e)
- {
- System.err.println("Драйвер не зарегистрировался");
- }
- try
- {
- connection = DriverManager.getConnection(URL,USERNAME,PASSWORD);
- if(!connection.isClosed())
- {
- System.out.println("Соединение установлено");
- }
- }
- catch(SQLException ex)
- {
- System.err.println("Соединение не установлено");
- }
- finally
- {
- if (connection != null) try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment