cancel
Showing results for 
Search instead for 
Did you mean: 

sqlj class definition --> cannot resolve in other classes

Former Member
0 Kudos

Hy @all,

i try to learn WebDynPro for Java. Therefore I leran some basics. Now: Database / SQLJ / EJB /

I have a EJB Project a Webproject and a application project. IN the EJB Project I have a sqlj Datei with DataAccess.

public class EmployeeDAO {

public static void main(String[] args) {

}

public void createEmployeeDAO (EmployeeDTO employeeDTO)

throws SQLException {

SQLJConnection connCtx = null;

try {

connCtx = new SQLJConnectionCtx();

#sql [connCtx] {insert into ja300_10employee

(employee_id, first_name, last_name, email)

values

(:(employeeDTO.getEmployeeId()),

:(employeeDTO.getFirstName()),

:(employeeDTO.getLastName()),

:(employeeDTO.getEmail()))

};

} finally {

if connCtx != null) {

connCtx.close();

}

}

}

}

But when I try to create an intance of the class the nwds says: can not resolve....

What goes wrong?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Where you are creating object for EmployeeDAO class? In WebDynpro or in EJB project?

Are you using Development Components?

For example if you have created the EmployeeDAO in java DC and if you want to use this in EJB DC/WebDynpor DC , you need to add this class to the public part (api) and then you need to add this public part as used dc in the DC where you want to create the object.

Regards,

Charan

Former Member
0 Kudos

Hy,

I don't use DCs. First of all I want to lern the Basics to Jave

one file is: EmployeeDAO.sqlj .. how can I use it? I want in a other file EmployeeDTO.java have an instance of the sqlj....

Or: How have I use the sqlj file? (Im try soe excercises from JA300!)

regards

nitin_mahajan2
Contributor
0 Kudos

Michael, these 3 apps that you mentioned, how are they linked?

How are you referencing them?

As far as the code is concerned, i dont see a reference to the class in the main method.

or if you dont have the main method you need to have a empty constructor of the class.

Regards,

Nitin

Former Member
0 Kudos

Hy an thx for your help,

first of all I have set the reference to the projects. In the package: com.sap.training.dbaccess are the following files:

EmployeeDAO.sqlj

EmployeeDAO.java (empty)

EmployeeDTO.java

SQLJConnection.sqlj

SQLJConnection.sqlj (empty)

in the package: com.sap.training.ejb i have the SessionBean an in this class I want to have a reference to the EmployeeDAO object as follow:

public class EmployeeSessionBean implements SessionBean {
	
	private EmployeeDAO employeeDAO;
	

	public void ejbRemove() {
	}

	public void ejbActivate() {
	}

	public void ejbPassivate() {
	}

	public void setSessionContext(SessionContext context) {
		myContext = context;
	}

	private SessionContext myContext;
	/**
	 * Business Method.
	 */
	public void createEmployee(EmployeeDTO employeeDTO)
			throws EmployeeException {
				
				try {
					employeeDAO.createEmployee(employeeDTO);
				} catch (SQLException e) {
					e.printStackTrace();
					throw new EmployeeException("Error while creating new employee: " + e.getMessage());		
				}
	}


	/**
	 * Create Method.
	 */
	public void ejbCreate() throws CreateException {
		// TODO : Implement
		employeeDAO = new EmployeeDAO();
	}

}

The second line is the bad one An sqlj file i have to use, if i handle with dataaccess / sql statements. Can I have an instance of an sqlj class?

regards