Problema com a pesquisa no banco

Galera estou com um problema para fazer uma simples pesquisa no banco.
Sou muito leigo na parte de banco de dados, e estou começando a ver realmente agora.
Vou colocar aqui o erro que está acontecendo e as classes envolvidas…
Obs: eu sei que está feio os códigos java na JSP, mas é só para teste…

org.apache.jasper.JasperException: An exception occurred processing JSP page /exibeAluno.jsp at line 25

22:
23: <% AlunoDAO alunoDAO = new AlunoDAO(); %>
24: <% String nome = request.getParameter(“nome”); %>
25: <% alunoDAO.procura(“Gustavo”); %>
26: <% Aluno aluno = new Aluno(); %>
27:


28:

root cause

javax.servlet.ServletException: java.sql.SQLException: No value specified for parameter 1
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.exibeAluno_jsp._jspService(exibeAluno_jsp.java:121)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

root cause

java.sql.SQLException: No value specified for parameter 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2176)
com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2100)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1826)
br.com.dao.AlunoDAO.procura(AlunoDAO.java:88)
org.apache.jsp.exibeAluno_jsp._jspService(exibeAluno_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

[code]package br.com.dao;

import br.com.modelo.*;  
import java.sql.*;  
import java.util.ArrayList;  

import java.util.List;

public class AlunoDAO {  
 
   // a conexão com o banco de dados  
   private Connection connection;  

   // construtor que recebe a conexão  
   public AlunoDAO(Connection con) {  
       this.connection = con;  
   }  
 
   public AlunoDAO() throws SQLException {  
       this.connection = ConnectionFactory.getConnection();  
   }  
 
   public void adiciona(Aluno aluno) throws SQLException {  
 
       // prepared statement para inserção  
       PreparedStatement stmt = this.connection  
               .prepareStatement("insert into aluno " +
               "(nome,matricula,nome_mae,data) values (?, ?, ?, ?)");  
 
       // seta os valores  
       stmt.setString(1, aluno.getNome());  
       stmt.setString(2, aluno.getMatricula());  
       stmt.setString(3, aluno.getNome_Mae());
       stmt.setString(4, aluno.getData_Escola()); 
 
       // executa  
       stmt.execute();  
       stmt.close();  
   }  
 
   public List<Aluno> getLista() throws SQLException {  
 
       PreparedStatement stmt = this.connection.prepareStatement("select * from aluno");  
       ResultSet rs = stmt.executeQuery();  
 
       List<Aluno> list = new ArrayList<Aluno>();  
       while (rs.next()) {  
           // criando o objeto Contato   
    	   Aluno aluno = new Aluno();  
    	   aluno.setId_aluno(rs.getInt("id_aluno"));  
    	   aluno.setNome(rs.getString("nome"));  
    	   aluno.setMatricula(rs.getString("matricula"));  
    	   aluno.setNome_Mae(rs.getString("nome_mae"));
    	   aluno.setData_Escola(rs.getString("data"));
 
           // adicionando o objeto à lista  
           list.add(aluno);  
       }  
 
       rs.close();  
       stmt.close();  
 
       return list;  
   }  
    
   public Aluno procura(String nome) throws SQLException {  
       PreparedStatement stmt = connection.prepareStatement("select * from aluno where nome=?");  
       ResultSet rs = stmt.executeQuery(); 
         
       if(!rs.next()) return null;  
 
       Aluno a = new Aluno();  
       a.setId_aluno(rs.getInt("id"));  
       a.setNome(rs.getString("nome"));  
       a.setMatricula(rs.getString("matricula"));  
       a.setNome_Mae(rs.getString("nome_mae")); 
       a.setData_Escola(rs.getString("data"));
      rs.close();  
       stmt.close();
      return a;   
   }  

} [/code]

Bom é isso, espero que possam me ajudar, estou precisando disso pra ontem… =(
Qualquer ajuda é bem vinda, valeu!

Não tenho certeza, mas acho que voce tem que setar o parametro usado no sql

algo como:
stmt.setString(1, nome);

Espero que ajude, apesar que nem testei aqui XDDDD

[quote=fabiorlopes]Não tenho certeza, mas acho que voce tem que setar o parametro usado no sql

algo como:
stmt.setString(1, nome);

Espero que ajude, apesar que nem testei aqui XDDDD[/quote]

É isso aí!

 public Aluno procura(String nome) throws SQLException {    
            PreparedStatement stmt = connection.prepareStatement("select * from aluno where nome=?");    
            //faltou informar o valor do parametro!!!
            stmt.setString(1, nome);
            //-----------------------------------
            ResultSet rs = stmt.executeQuery();   
                
            if(!rs.next()) return null;    
        
            Aluno a = new Aluno();    
            a.setId_aluno(rs.getInt("id"));    
            a.setNome(rs.getString("nome"));    
            a.setMatricula(rs.getString("matricula"));    
            a.setNome_Mae(rs.getString("nome_mae"));   
            a.setData_Escola(rs.getString("data"));  
           rs.close();    
            stmt.close();  
           return a;     
        }   
1 curtida