You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@beehive.apache.org by Timothy Brown <tb...@earthlink.net> on 2005/01/24 20:04:03 UTC

Exception caught: Invalid argument name in SQL statement

I am getting this error and have no idea where to troubleshoot.  I know the
sql statement is correct..I have the latest code from svn compiled and
deployed.

 

Any ideas?

 

Thanks,

 

Tim

 

 

Employee.jsp

 

<%@ page language="java" contentType="text/html;charset=UTF-8"%>

<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0"
prefix="netui"%>

<netui:html>

  <head>

    <title>Employee Test Page</title>

  </head>

  <netui:body>

    <jsp:useBean class="controls.employee.EmployeeManagerBean" id="empMgr"
scope="session"/>

    <p>

        Response from the selectEmployee() method on the Employee Manager
Control: <strong> <%= empMgr.selectEmployee() %> </strong>

    </p>

    <p>

        Response from the getEmployee() method on the Employee Manager
Control: <strong> <%= empMgr.getEmployee() %> </strong>

    </p>

    

  </netui:body>

</netui:html>

 

 

 

EmployeeDBControl.jcx

 

package controls.employee;

 

import java.sql.SQLException;

import java.sql.ResultSet;

 

import java.io.Serializable;

 

import java.util.Iterator;

import java.util.HashMap;

 

import org.apache.beehive.controls.api.bean.ControlExtension;

 

import dbControl.DatabaseControl;

import dbControl.DatabaseControl.ConnectionDataSource;

import dbControl.DatabaseControl.SQL;

 

@ControlExtension

@ConnectionDataSource(jndiName="jdbc:hsqldb:hsql://localhost, sa")

public interface EmployeeDBControl extends DatabaseControl

{   

    @SQL(statement="SELECT employee_id, first_name, last_name FROM EMPLOYEE
WHERE employee_id={ i }")

    public Employee selectEmployee( int i ) throws SQLException;

    

    //

    // get all rows from the EMPLOYEE table, returned as a
java.sql.ResultSet 

    //

    @SQL(statement="SELECT * FROM EMPLOYEE")

    public ResultSet getAllEmployees() throws SQLException;    

    

}

 

EmployeeManagerImpl.jcs

 

package controls.employee; 

 

import org.apache.beehive.controls.api.bean.*;

import java.sql.SQLException;

import java.rmi.RemoteException;

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.Statement;

import java.sql.ResultSet;

 

import javax.sql.DataSource;

import javax.naming.InitialContext;

import javax.naming.Context;

 

 

@ControlImplementation

public class EmployeeManagerImpl implements EmployeeManager

{ 

 

    @Control EmployeeDBControl employeeDB;

   

    Employee emp = null;

 

            

            // default no-arg constructor

            public EmployeeManagerImpl(){}

                        

    public String getEmployee()

    {

        return "Change to Employee control";

    }

   

    public String getAllEmployees() 

    {

         String sRetVal = "nada";

         ResultSet rs = null;

         try

         {

              System.out.println( "EmployeeManagerImpl: Calling
employeeDB.getAllEmployees..." );

              rs = employeeDB.getAllEmployees();

              //Customer[] customers jdbcCtrl.getCustomerArray();

        

             if( rs.next() ) 

             {

                sRetVal = "We have data in the result set" ;

             }

         }

         catch( SQLException sqle )

         {

          // TODO

              System.out.println( sqle.getMessage() );

         }

        return sRetVal;

    }

    

            public String selectEmployee()

            {

                        

                        String sRetVal = "Something is wrong -- Returned
from selectEmployee in EmployeeManagerImpl";

                

                try

                {

             System.out.println("EmployeeManagerImpl: Attemping to call
employeeDB.selectEmployee( 100 ) ");

                    emp = employeeDB.selectEmployee( 100 );

             System.out.println("EmployeeManagerImpl: Fininshed calling
employeeDB.selectEmployee( 100 ) ");

                }

                catch( SQLException sqle )

                {

                    sRetVal = "SQLException caught: " + sqle.getMessage();

                }

 

                catch( Exception e )

                {

                    sRetVal = "Exception caught: " + e.getMessage();

                }

                        

                        if ( null != emp )

                        {

                            sRetVal = emp.toString();

                        System.out.println("sRetVal contains data: " +
sRetVal );                  

                        }

                        

                        return sRetVal;

            }

 

 

 

 

 

    public String testDriverMgrConnection() throws Exception 

    {

            String sRetVal = "Nada";

            

              int iEmpId = 0;

              String foo = "Not Connected";

                          String bar = "No Last Name";

/*          

            Class.forName("org.hsqldb.jdbcDriver");

 

        // add authentication and test

        Connection conn =
DriverManager.getConnection("jdbc:hsqldb:hsql://localhost, sa");

        Statement s = conn.createStatement();

        

        if ( conn != null )

        {

            System.out.println("Conn is not null in
testDriverMgrConnection");

            sRetVal = "conn is not null";

        }

 

        conn.close();

        s = null;

 

*/

     

    try

    {

      Context initCtx = new InitialContext();

      if(initCtx == null ) 

          throw new Exception("Boom - No Context");

 

      //DataSource ds = 

 
//(DataSource)initCtx.lookup("java:comp/env/com.bea.EventTracker");

            

                        Context envCtx = (Context)
initCtx.lookup("java:comp/env");

                        DataSource ds = (DataSource)

                        envCtx.lookup("com.bea.EventTracker");            

 

      if (ds != null) 

      {

        Connection conn = ds.getConnection();

              

        if(conn != null)  

        {

            foo = "Got Connection "+conn.toString();

            Statement stmt = conn.createStatement();

            ResultSet rst = 

                stmt.executeQuery(

                  "select employee_id, last_name, first_name from
employee");

            if(rst.next()) 

            {

               iEmpId = rst.getInt(1);

               foo    = rst.getString(2);

               bar    = rst.getString(3);

               

               sRetVal = iEmpId + " " + bar + " "+ foo ;

            }

            conn.close();

        }

      }

    }catch(Exception e) 

    {

      //e.printStackTrace();

      sRetVal = e.getMessage();

    }

     

        return sRetVal;

 

    }

 

}

 

EmployeeManager.java

 

package controls.employee; 

 

import org.apache.beehive.controls.api.bean.ControlInterface;

import java.sql.SQLException;

import java.sql.ResultSet;

 

@ControlInterface

public interface EmployeeManager

{ 

    public String getEmployee();

    

    public String selectEmployee();

    

            public String testDriverMgrConnection() throws Exception;

     

     public String getAllEmployees() throws SQLException;     

    

}