2 Replies Latest reply on Oct 4, 2003 3:50 AM by username

    SQLException: Table not found

      When I try to query a table on a database from a session bean I
      get the following :
      SQLException java.sql.SQLException: Table not found: mytable in statement [select * from mytable]

      I stated that neither my connection or my datasource are null.

      The same query from a jsp page with the same DataSource works...

      This is my code.
      Any help is appreciated....
      Thanks.
      u

      .....
      try {
      initCtx = new InitialContext();
      envCtx = (Context) initCtx.lookup("java:comp/env");


      ds = (DataSource) envCtx.lookup("jdbc/myds");
      } catch (NamingException ne) {
      test += "NamingException " + ne;
      }


      if (ds !=null) {

      try {
      conn = ds.getConnection();
      //query = new Query(conn);
      if (conn == null) test += "Cconn is null ";
      else test += "conn is not null";
      } catch (SQLException sqle) {
      System.out.println("SQLException " + sqle);
      test += "Conn is null";
      }

      try {

      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("select * from mytable");

      if (rs.next()) {
      test += "---------------" + rs.getString(1);

      } else
      test += "no results";


      stmt.close();
      } catch (SQLException sqle) {
      System.out.println("SQLException " + sqle);
      test += "SQLException " + sqle;
      }
      ........


      if I print test variable I get :

      conn is not null
      SQLException java.sql.SQLException: Table not found: mytable in statement [select * from mytable]



      Below my ejb-jar.xml and jboss.xml

      ejb-jar.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
      <ejb-jar>
      <enterprise-beans>

      Deployment descriptor for Protocollo Bean
      <display-name>MyBean</display-name>
      <ejb-name>MyEJB</ejb-name>
      MyclassHome
      Myclass
      <ejb-class>MyclassBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>
      <resource-ref>
      <res-ref-name>jdbc/myds</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>



      </enterprise-beans>
      </ejb-jar>


      jboss.xml

      <?xml version="1.0" encoding="UTF-8" ?>

      <enterprise-beans>

      <ejb-name>MyEJB</ejb-name>
      <jndi-name>ejb/MyEJB</jndi-name>
      <resource-ref>
      <res-ref-name>jdbc/myds</res-ref-name>
      <resource-name>Data source protocollo</resource-name>
      </resource-ref>


      </enterprise-beans>