NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
dish.balur
Joined: 04 Mar 2011 Posts: 6 Location: Belgaum
|
Posted: Wed Mar 16, 2011 10:09 am Post subject: EJBException |
|
|
Hello !!
I have a problem regarding EJB in my project.
I have a form where in the customer has to login using his username and password.
I have created the entity bean and session bean .I have created a servlet that calls the bean.
The project compiles successfully. But when I enter the user name and password its gives the exception Login Failed javax.ejb.EJBException
I checked the server log file. Here is what it says:
Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of UserName that does not exist in the query string SELECT c FROM Customer c WHERE c.userName = :userName.
I have checked the parameters . It seems to be correct. Please let me know what might be the problem. |
|
| Back to top |
|
 |
Steven Siebert Posted via mailing list.
|
Posted: Wed Mar 16, 2011 9:56 pm Post subject: Re: EJBException |
|
|
Can you please post the code where you are instantiating the Query and setting the parameters?
Thanks,
S
On Wed, Mar 16, 2011 at 6:09 AM, dish.balur <address-removed ([email]address-removed[/email])> wrote:
| Quote: | Hello !!
I have a problem regarding EJB in my project.
I have a form where in the customer has to login using his username and password.
|
|
| Back to top |
|
 |
dish.balur
Joined: 04 Mar 2011 Posts: 6 Location: Belgaum
|
Posted: Thu Mar 17, 2011 8:16 am Post subject: |
|
|
Hello,
This is the entity bean :
@Entity
@Table(name = "CUSTOMER")
@NamedQueries( {
@NamedQuery(name = "Customer.findByCustId", query = "SELECT c FROM Customer c WHERE c.custId = :custId"),
@NamedQuery(name = "Customer.findByUserName", query = "SELECT c FROM Customer c WHERE c.userName = :userName"),
@NamedQuery(name = "Customer.findByPassword", query = "SELECT c FROM Customer c WHERE c.password = :password"),
@NamedQuery(name = "Customer.findByFullName", query = "SELECT c FROM Customer c WHERE c.fullName = :fullName"),
public class Customer implements Serializable {
@Id
@Column(name = "CUST_ID", nullable = false)
private Integer custId;
@Column(name = "USER_NAME")
private String userName;
@Column(name = "PASSWORD")
private String password;
The Session bean:
public List findCustomerByUserName(String UserName)
{
List cust=em.createNamedQuery("Customer.findByUserName").setParameter("UserName",UserName).getResultList();
return customer;
}
public String persist(Object obj)
{
String message= "Success";
if(obj instanceof Customer)
{
Customer custs=(Customer) obj;
if (custs.getCustId()==0)
{
InitialContext ctx;
try
{
ctx=new InitialContext();
DataSource ds= (DataSource) ctx.lookup("jdbc/innovative");
Connection con= ds.getConnection();
Statement stmt=con.createStatement();
ResultSet rs= stmt.executeQuery("select 1 from Customer where user_Name='"+custs.getUserName()+"'");
if(rs.next())
{
message="User Name already exists.Please select a different UserName";
}
rs=stmt.executeQuery("select max(cust_Id) from customer");
if(rs.next())
{
custs.setCustId(rs.getInt(1)+1);
}
else
{
custs.setCustId(1);
}
stmt.close();
ctx.close();
}
catch(NamingException ex)
{
ex.printStackTrace();
}
catch(SQLException ex)
{
ex.printStackTrace();
}
}
}
if("Success".equals(message))
em.persist(obj);
return message;
} |
|
| Back to top |
|
 |
dish.balur
Joined: 04 Mar 2011 Posts: 6 Location: Belgaum
|
Posted: Thu Mar 17, 2011 8:19 am Post subject: |
|
|
This is the code that looks up the bean:
<%
String UserName=request.getParameter("User Name");
String password=request.getParameter("Password");
if(UserName!=null && password!=null)
{
try
{
InitialContext ic=new InitialContext();
Object o=ic.lookup("java:comp/env/IndoorsessionLocal");
IndoorsessionLocal Indoorsession=(IndoorsessionLocal) o;
List custlist=Indoorsession.findCustomerByUserName(UserName);
if(custlist!=null && custlist.size()>0)
{
Customer cus=(Customer)custlist.get(0);
if(password.equals(cus.getPassword()))
{
session.setAttribute("CustId",cus.getCustId());
response.sendRedirect("Welcome.jsp");
}
}
}
catch(Exception e)
{
out.println("Login Failed"+e.toString());
}
}
%> |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|