Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class ConnectorDB {
- static Connection connection = null;
- public final static String url = "jdbc:mysql://localhost/shop";
- public final static String name = "root";
- public final static String password = "root";
- public ConnectorDB() {
- try {
- //Загружаем драйвер
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Драйвер подключен");
- //Создаём соединение
- connection = DriverManager.getConnection(url, name, password);
- System.out.println("Соединение установлено");
- } catch (Exception ex) {
- //выводим наиболее значимые сообщения
- Logger.getLogger(JDBCtest.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- }
- }
- public Connection getConnection() {
- return connection;
- }
- public boolean login(String email, String password) {
- Statement statement = null;
- boolean res = false;
- try {
- statement = connection.createStatement();
- ResultSet result1 = statement.executeQuery(
- "SELECT * FROM users where email = '" + email + "'");
- while (result1.next()) {
- System.out.println(result1.getString("password"));
- if (result1.getString("password").equals(password))
- res = true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- close();
- return res;
- }
- private void close() {
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException ex) {
- Logger.getLogger(JDBCtest.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement