Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Can any One answer it !!!!!!!!!!!!!!!!!!!!!

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Can any One answer it !!!!!!!!!!!!!!!!!!!!!

    how to send the form data to database using servlets and hibernate???????

    m getting org.hibernate.Session. showing ClassNotFoundException..

    help!!!!!!!!!!!!!!!!!

    mycode:
    login.jsp
    <form action="Servlet" >
    id
    <input type="text" name="id"></br>
    username
    <input type="text" name="username"></br>
    lastname
    <input type="text" name="lastname"></br>
    <input type="submit" value="submit">
    </form>
    hibernate.cfg.xml

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

    <hibernate-configuration>

    <session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">oracle.jdbc.driver. OracleDriver</property>
    <property name="connection.url">jdbcracle:thin:@localhost:1521:XE</property>
    <property name="connection.username">system</property>
    <property name="connection.password">system</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">2</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.OracleDialect </property>

    <!-- Enable Hibernate's current session context -->
    <property name="current_session_context_class">org.hibernate .context.ManagedSessionContext</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.No CacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>

    <mapping resource="com/com/Person.hbm.xml"/>

    </session-factory>

    </hibernate-configuration>

    Pojo:
    Person.java

    package com.com;

    public class Person {
    private String id;
    private String username;
    private String lastname;
    public String getId() {
    return id;
    }
    public void setId(String id) {
    this.id = id;
    }
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }
    public String getLastname() {
    return lastname;
    }
    public void setLastname(String lastname) {
    this.lastname = lastname;
    }


    }


    servlet.java
    package com.com;

    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;

    /**
    * Servlet implementation class Servlet
    */
    public class Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    public Servlet() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out=response.getWriter();
    String s1=request.getParameter("id");
    String s2=request.getParameter("username");
    String s3=request.getParameter("lastname");

    Session s=HibernateUtil.getSession();

    Person p=new Person();
    //p.setId(s1);
    p.setUsername(s2);
    p.setLastname(s3);
    s.beginTransaction();
    s.save(p);
    s.getTransaction().commit();
    s.flush();
    s.close();
    System.out.println("done");
    out.print("done");
    out.close();














    }

    }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Can any One answer it !!!!!!!!!!!!!!!!!!!!!

    The best I can guess is that you are missing the dependency for org.hibernate.Session (I think it is a JBoss dependency?).
    If the program compiles correctly but throws this exception during deployment, this would indicate that the dependency does not exist at runtime. If you are running your program on a server, your first step would be seeing if you can find the dependency in the server files. Depending on how you deploy to your server, you can sometimes have issues where the dependencies are not deploying alongside your product.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Replies: 3
    Last Post: March 9th, 2013, 07:22 PM
  2. Can somebody help me to answer this? Thanks!
    By dshainad in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 13th, 2012, 09:47 PM
  3. What's ur answer?
    By Tanmaysinha in forum The Cafe
    Replies: 6
    Last Post: October 12th, 2011, 06:26 AM
  4. need answer for these
    By satishbs in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2011, 01:46 AM