Conectar a base de dados

1 resposta
R

Bom dia Pessoal;

Estou usando o Win XP, IDE Netbeans 6.7.1.
Meu problema é o seguinte. Estou fazendo um teste de validação de login, onde a primeira tela solicita o CPF e a Senha.
Ao clicar no botão “Confirmar”, terei que verificar se o CPF existe na base de dados e se a senha está correta.
Não estou conseguindo fazer isto rodar.

Segue abaixo o meu exemplo.
As linhas em vermelho, são onde a IDE acusa erro.
O que está errado ?

Desde já agradeço

<%–
Document : index
Created on : Oct 2, 2009, 1:15:45 PM
Author : RGOMIDE
–%>

<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
<%@ taglib prefix=“sql” uri=“http://java.sun.com/jsp/jstl/sql” %>

<%@page contentType=“text/html” pageEncoding=“UTF-8”%>

<%@ page import=“java.sql.*” %>
<%@ page import=“javax.swing.JOptionPane” %>

FARMATADS
<script language="JavaScript">
        function Validar()
        {
            if (document.Index.CPF.value == "")
                {
                    alert("Forneça o CPF.");
                    document.Index.CPF.focus();
                }
            else if (document.Index.SENHA.value == "")
                {
                    alert("Forneça a senha.");
                    document.Index.SENHA.focus();
                }
            else
            {
               try
                {
                   Class.forName("com.mysql.jdbc.Driver").newInstance();
[color=red]                       Connection con = DriverManager.getConnection(jdbc:mysql://localhost/db_farmatads,root,nosbor);

Statement statement = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_READ_ONLY);
ResultSet resultset = statement.executeQuery("select senha_fun from tfuncionario where cpf_fun='" + document.Index.CPF + "'");[/color]
                   resultset.last();
                   if (resultset.getRow() == 0)
                      {
                         JOptionPane.showMessageDialog(null, "CPF não cadastrado!");
                         return false;
                      }
                   else
                      {
[color=red]                             String s = resultset.getString(1);[/color]

if (s.equals(document.Index.SENHA.value))

{

alert(“Acesso concedido”);

return true;

}

else

{

alert(“Senha Inválida !”);

document.Index.SENHA.focus();

return false;

}

}

} catch (e)

{

alert("Erro Cmdo SQL " + e.getMessage());

return false;

} finally

{

return false;

}

}

}
<body>
    <form name="Index" action="ValidaLogin.jsp" method="post" onsubmit="return Validar()">
       <table width="100%" border="0" bgcolor="rgb(179,217,255)">
           <tbody>
               <tr>
                   <th>
                       <b>Prática II - Parte II - UNITINS - Grupo "Turma UDI"</b>
                   </th>
               </tr>
               <tr>
                   <th>
                       <img src="FARMATADS_2.PNG" width="139" height="31" alt="FARMATADS_2"/>
                   </th>
               </tr>
           </tbody>
       </table>

       <p></p>
       <br><br><br>
       <center>
           <b><h3>Login</h3>
               <br><br><br>
               CPF..:  <input type="text" name="CPF" value="" size="12" maxlength="11" />
               <br>
               Senha: <input type="password" name="SENHA" value="" size="13" maxlength="11"/>
           </b>
       </center>
       <br><br>
       <center>
          <input type="submit" value="Confirmar" name="Confirmar" />
       
          <input type="reset" value="Limpar" name="Limpar" />
       </center>
    </form>
</body>

1 Resposta

M

Vc ja testou se sua conexão esta efetuando com sucesso, faça a conexão e faça um try/catch para retornar a mensagem de erro caso não esteja conectando corretamente.

Att.

Criado 13 de outubro de 2009
Ultima resposta 3 de nov. de 2009
Respostas 1
Participantes 2