Beginner |
|
Joined: Wed Jul 18, 2007 7:38 am Posts: 23
|
i am new to hibernate so please clear my exception when i try to use jsf with hibernate i am getting this exception.
Exception:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: #{login.addManager}: javax.faces.el.EvaluationException: org.hibernate.exception.SQLGrammarException: Cannot open connection
javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)
root cause
javax.faces.FacesException: #{login.addManager}: javax.faces.el.EvaluationException: org.hibernate.exception.SQLGrammarException: Cannot open connection
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.17
Login.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title></title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="UserName" />
<h:inputText value="#{login1.id}" />
<h:outputText value="Password"/>
<h:inputText value="#{login1.passwd}" />
<h:commandButton action="#{login1.addManager}" value="Submit" />
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
LoginManager.java
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class LoginManager
{
public LoginManager(int id,String Password)
{
Session session = null;
try
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record1");
Login contact = new Login();
System.out.println("Inserting");
//contact.setFirstName("shiva");
contact.setId(id);
contact.setPasswd(Password);
session.save(contact);
System.out.println("Done2");
}
catch(Exception e)
{
System.out.println("Error"+e);
}
finally
{
// Actual contact insertion will happen at this step
session.beginTransaction().commit();
session.flush();
session.close();
}
}
public static void main(String[] args)
{
new LoginManager(1,"ss");
}
}
|
|