Bom dia pessoal, tudo bem?
Estou com esse problema na hora que rodo o projeto, na página de login abre essa mensagem e o sistema não loga.
Aqui vai a classe do banco:
package Util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConexaoBD {
public Connection conectar() throws SQLException {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://localhost/projetointegrador");
} catch (ClassNotFoundException e)
{
throw new RuntimeException(e);
}
}
private static final String USERNAME = "root";
private static final String PASSWORD = "537607";
private static final String DATABASE_URL = "jdbc:mysql://localhost:3306/projetointegrador";
public static Connection createConnectionToMySQL() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = (Connection) DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
return connection;
}
public static void main(String[] args) throws Exception{
Connection con = createConnectionToMySQL();
if(con != null){
System.out.println("Conexão obtida com sucesso!" + con);
con.close();
}
}
}
Classe da página Index:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<!------ Include the above in your HEAD tag ---------->
<%@page import="Util.ConexaoBD"%>
<%@page import="java.sql.*"%>
<%@page import="com.mysql.jdbc.Driver"%>
<%@ page language="java" contentType="text/html" pageEncoding="ISO-8859-1" import="java.sql.*" %>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Login</title>
</head>
<body class="background">
<%
Statement st;
ResultSet rs;
%>
<div id="logreg-forms">
<form method="post" action="index.jsp" class="form-signin" >
<div style="text-align: center; padding-bottom: 4%;"><img src="user-login.png"></div>
<h1 class="h3 mb-3 font-weight-normal" style="text-align: center">Login</h1>
<input type="email" id="inputEmail" name="email" class="form-control" placeholder="Endereço de E-mail"
required>
<input type="password" id="inputPassword" name="senha" class="form-control" placeholder="Senha" required>
<button class="btn btn-success btn-block" type="submit"><i class="fa fa-sign-in"></i> Entrar</button>
</form>
<p style="text-align: center; color: red;" class="text-light-m2">
<%
//RECEBENDO DADOS DOS INPUTS
String email_1 = request.getParameter("email");
String senha = request.getParameter("senha");
String nomeUsuario = "";
String pegaEmail = "";
String pegaSenha = "";
int i = 0;
try {
//CONECTANDO AO BANCO DE DADOS
st = new ConexaoBD().conectar().createStatement();
rs = st.executeQuery("SELECT * FROM usuarios "
+ "WHERE email = '"+email_1+"' AND senha = '"+senha+"'");
while (rs.next()) {
pegaEmail = rs.getString(5);
pegaSenha = rs.getString(3);
nomeUsuario = rs.getString(2);
rs.last();
i = rs.getRow();
System.out.println("Logou");
}
} catch (Exception e) {
out.println(e);
}
if (email_1 == "" || senha == "" || email_1 == null || senha == null)
{
%> <div class="alert alert-danger" style="text-align: center">
<strong>Preencha os campos!</strong></div> <%
}
else
{ if (i > 0)
{
session.setAttribute("nomeUsuario", nomeUsuario);
response.sendRedirect("home.jsp");
}
else {
%> <div class="alert alert-danger" style="text-align: center">
<strong>E-mail ou senha incorretos!</strong></div> <%
}
}
%>
</p> </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="/script.js"></script>
</body>
</html>