ola a todos
o que pode estar ocorrendo com o seguinte servlet, estou usando eclipse + jboss + lomboz + mysql, ele retorna a excessão:
package servlets;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import vos.ProdutoVO;
import exceptions.ExcecaoNegocio;
public class ManterProdutoServlet extends HttpServlet
{
public void init( ServletConfig config ) throws ServletException
{
super.init( config );
}
protected void doGet( HttpServletRequest request,
HttpServletResponse response ) throws ServletException, IOException
{
doPost( request, response );
}
protected void doPost( HttpServletRequest request,
HttpServletResponse response ) throws ServletException, IOException
{
System.out.println( "Iniciando o doPost" );
System.out.println( "Pegando Sessao" );
HttpSession session = request.getSession( true );
ProdutoVO prodVO = ( ProdutoVO ) session.getAttribute( "produtoVO" );
if ( prodVO == null )
{
prodVO = new ProdutoVO();
session.setAttribute( "produtoVO", prodVO );
}
System.out.println( "Pegando os dados do request" );
String operacao = request.getParameter( "operacao" );
String codigo = request.getParameter( "codigo" );
String nome = request.getParameter( "nome" );
String descricao = request.getParameter( "descricao" );
String valor = request.getParameter( "valor" );
System.out.println( "Transformando valores do request" );
int cod;
if ( ( codigo != null ) && ( !codigo.equals( "" ) ) && ( !codigo.equals( " " ) ) )
cod = ( new Integer( codigo ) ).intValue();
else
cod = 0;
Double val;
if ((valor != null) && (!valor.equals("")) && (!valor.equals("")))
val = new Double(valor);
else
val = new Double(0);
System.out.println( "Sincronizando tela com objeto" );
// Sincronizar objeto da Sessao com a Tela
prodVO.setCodigo(cod);
prodVO.setNome(nome);
prodVO.setDescricao(descricao);
prodVO.setValor(val);
prodVO.setMensagem("");
System.out.println( "Valor de codigo " + prodVO.getCodigoStr() );
System.out.println( "Valor de nome " + prodVO.getNome() );
System.out.println( "Valor de descricao " + prodVO.getDescricao() );
System.out.println( "Valor de valor " + prodVO.getValorStr() );
try
{
System.out.println("Pegando a conexao JDBC");
Connection con = null;
InitialContext ctx = new InitialContext();
DataSource ds = ( DataSource ) ctx.lookup( "java:/jdbc/Vendas" );
con = ds.getConnection();
System.out.println("Iniciando as operacoes");
if ( operacao.equals( "I" ) )
{
if ( cod == 0 ) throw new ExcecaoNegocio( "Codigo deve ser diferente 0 (zero)!" );
if ( (nome == null) || (nome.equals("")) || (nome.equals(" ")) )
throw new ExcecaoNegocio("Por favor, informar um nome!");
PreparedStatement pstmt = con.prepareStatement(
"INSERT INTO PRODUTO(CODIGO, NOME, DESCRICAO, VALOR)" +
" VALUES( ?, ?, ?, ?)" );
pstmt.setInt(1, cod);
pstmt.setString(2, nome);
pstmt.setString(3, descricao);
pstmt.setDouble(4, val.doubleValue());
int ret = pstmt.executeUpdate();
prodVO.setMensagem("Produto incluido com sucesso!");
} else {
if (operacao.equals("C")) {
if (cod == 0) throw new ExcecaoNegocio("Codigo deve ser diferente 0 (zero)!");
PreparedStatement pstmt = con.prepareStatement(
"SELECT CODIGO, NOME, DESCRICAO, VALOR FROM PRODUTO" +
" WHERE CODIGO = " + String.valueOf(cod));
ResultSet rs = pstmt.executeQuery();
if ( rs.next() )
{
prodVO.setCodigo(rs.getInt("CODIGO"));
prodVO.setNome(rs.getString("NOME"));
prodVO.setDescricao(rs.getString("DESCRICAO"));
prodVO.setValor(new Double( rs.getDouble("VALOR") ) );
prodVO.setMensagem("");
} else {
prodVO.setCodigo(0);
prodVO.setNome("");
prodVO.setDescricao("");
prodVO.setValor(new Double(0) );
prodVO.setMensagem("Nenhum produto foi encontrado para este código!");
}
} else {
if (operacao.equals("A")) {
if (cod == 0) throw new ExcecaoNegocio("Código deve ser diferente 0 (zero)!");
if ( (nome == null) || (nome.equals("")) || (nome.equals(" ")) )
throw new ExcecaoNegocio("Por favor, informar um nome!");
PreparedStatement pstmt = con.prepareStatement(
"UPDATE PRODUTO SET NOME = ?, DESCRICAO = ?, VALOR = ? " +
" WHERE CODIGO = ?");
pstmt.setString(1, nome);
pstmt.setString(2, descricao);
pstmt.setDouble(3, val.doubleValue());
pstmt.setInt(4, cod);
int ret = pstmt.executeUpdate();
prodVO.setMensagem("Produto alterado com sucesso!");
} else {
if (operacao.equals("E")) {
if (cod == 0) throw new ExcecaoNegocio("Codigo deve ser diferente 0 (zero)!");
PreparedStatement pstmt = con.prepareStatement(
"DELETE FROM PRODUTO WHERE CODIGO = ?");
pstmt.setInt(1, cod);
int ret = pstmt.executeUpdate();
prodVO.setMensagem("Produto excluido com sucesso!");
}
}
}
}
} catch (NamingException ne) {
System.out.println("NamingException");
ne.printStackTrace();
prodVO.setMensagem("Problemas na localização do serviço JDBC!");
} catch (SQLException sqlex) {
System.out.println("SQLException");
prodVO.setMensagem("Problemas na interação com o banco de dados!");
} catch (ExcecaoNegocio en) {
System.out.println("ExcecaoNegocio");
prodVO.setMensagem(en.getMessage());
}
System.out.println("Operacoes concluidas, chamando JSP");
session.setAttribute("produtoVO", prodVO);
session.getServletContext().getRequestDispatcher("/ManterProdutoTela.jsp").forward( request, response);
System.out.println("Finalizando o Servlet");
}
}
retorna
NamingException
09:54:39,858 ERROR [STDERR] javax.naming.NameNotFoundException: jdbc not bound
09:54:39,862 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
09:54:39,864 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
09:54:39,865 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
09:54:39,866 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
09:54:39,868 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:528)
09:54:39,870 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
09:54:39,871 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:347)
09:54:39,872 ERROR [STDERR] at servlets.ManterProdutoServlet.doPost(ManterProdutoServlet.java:115)
09:54:39,872 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
09:54:39,872 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
09:54:39,872 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
09:54:39,872 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
09:54:39,872 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
09:54:39,873 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
09:54:39,873 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
09:54:39,873 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
09:54:39,873 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
09:54:39,873 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
09:54:39,873 ERROR [STDERR] at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
09:54:39,874 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
09:54:39,944 ERROR [STDERR] at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
09:54:39,949 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
09:54:39,951 ERROR [STDERR] at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
09:54:39,952 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
09:54:39,954 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
09:54:39,955 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
09:54:39,957 ERROR [STDERR] at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
09:54:39,959 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
09:54:39,960 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
09:54:39,962 ERROR [STDERR] at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
09:54:39,964 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
09:54:39,964 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
09:54:39,964 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
09:54:39,964 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
09:54:39,964 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
09:54:39,965 ERROR [STDERR] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
09:54:39,965 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
09:54:39,965 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
09:54:39,965 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
09:54:39,965 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
09:54:39,965 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
09:54:39,966 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
09:54:39,966 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
09:54:39,966 ERROR [STDERR] at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:197)
09:54:39,966 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
09:54:39,966 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
09:54:39,966 ERROR [STDERR] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
09:54:39,967 ERROR [STDERR] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
09:54:39,967 ERROR [STDERR] at java.lang.Thread.run(Thread.java:534)
o datasource ta como segue
<?xml version="1.0" encoding="UTF-8"?> MySqlDriver jdbc:mysql://localhost:3306/Vendas org.gjt.mm.mysql.Driver a bfalows