Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import com.mysql.cj.jdbc.Driver;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Main {
- private static final String URL = "jdbc:mysql://localhost:3306/pbz?useUnicode=true&useSSL=false&useJDBCCompliantTimezoneShift=true" +
- "&useLegacyDatetimeCode=false&serverTimezone=UTC";
- private static final String USERNAME = "root";
- private static final String PASSWORD = "123qwe";
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- Connection connection = null;
- Driver driver;
- try {
- driver = new com.mysql.cj.jdbc.Driver();
- DriverManager.registerDriver(driver);
- }
- catch (SQLException e1) {
- System.out.println("Драйвер не зарегистрировался");
- return;
- }
- try {
- connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
- if (!connection.isClosed())
- System.out.println("Соединение установлено");
- Statement statement = connection.createStatement();
- statement.execute("SELECT * FROM calls");
- }catch (SQLException ex){
- System.err.println("Соединение не установлено");
- ex.printStackTrace(); // Понадобился, чтобы отловить исключения, скрытые выводом на экран предупреждения
- return;
- } finally {
- if (connection != null) connection.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement