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 3 of 3

Thread: Need Expect Help and Advice

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Expect Help and Advice

    Am a novice and i have been trying to write a simple program
    to save three html form data ( name, email, age) to an access
    database using javabean and jsp. After days of struggling and
    reading tutorials from the net, i have succeded in debuging all
    error messages. my program is runing but the form data entered
    is not being saved into the access database. can some one examine
    my codes and tell me what to do and where I went wrong. yur help
    will be very much appreciated.
    Thanks

    Note: The progame is made up of five files A. B, C, D and E as ff:


    A. Database (ms access databas)

    Filename: savename --- Created with MS ACCESS 2007

    table: tblname
    nameid Autonumber Primary key
    name Char(50)
    email Char(80)
    age Int


    B. HTML FORM

    Filename: index.html

    Coded as ff:

    <HTML>
    <BODY>
    <FORM METHOD=POST ACTION="saveName.jsp">
    <table width="290" height="40" align="center">
    <tr>
    <td>Enter your name?</td>
    <td></td>
    <td><INPUT TYPE=TEXT NAME=name SIZE=20></td>
    <tr>

    <tr>
    <td>Enter your email?</td>
    <td></td>
    <td><INPUT TYPE=TEXT NAME=email SIZE=20></td>
    <tr>

    <tr>
    <td>Enter your age?</td>
    <td></td>
    <td><INPUT TYPE=TEXT NAME=age SIZE=4></td>
    <tr>

    <tr align="center">
    <td></td>
    <td></td>
    <td><P><INPUT TYPE=SUBMIT value="Save"></td>
    </tr>
    </table>
    </FORM>
    </BODY>
    </HTML>


    C. FORMBEAN

    Filename:userData.java
    coded as:

    package getname;

    public class userData {
    String name;
    String email;
    int age;

    public void setName( String myname )
    {
    this.name = myname;
    }

    public void setEmail( String mymail )
    {
    this.email = mail;
    }

    public void setAge( int myage )
    {
    this.age = myage;
    }

    public String getName()
    {
    return name;
    }

    public String getEmail()
    {
    return email;
    }

    public int getAge()
    {
    return age;
    }
    }



    D. DATA ACCESS JAVABEAN
    filename: dbbean.java
    Codes:

    package getname;

    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.net.*;



    public class dbbean

    {

    String name=null;
    String email=null;
    int age;

    Connection con = null;
    datasource dsndb="savename";
    String url = "jdbcdbc:dsndb";
    String driver = "jdbc.odbc.JdbcOdbcDriver";

    public void dbbean()

    {

    try{

    Class.forName(driver);
    con = DriverManager.getConnection(url,"","");
    try{

    Statement st = con.createStatement();
    int val = st.executeUpdate("INSERT INTO tblname(name, email, age) VALUES(?,?,?)");

    }

    catch (SQLException s)

    {

    System.out.println("SQL statement is not executed!");

    }

    }

    catch (Exception e){

    e.printStackTrace();
    }
    }
    }



    E. Action jsp file

    1.
    filename: saveName.jsp

    <jsp:useBean id="userform" class="getname.userData" scope="page"/>
    <jsp:setProperty name="userform" property="*"/>

    <jsp:useBean id="userdatabase" class="getname.dbbean" scope="request"/>
    <jsp:setProperty name="userdatabase" property="*"/>

    <HTML>
    <BODY align="center">
    <A HREF="NextPage.jsp">Continue</A>
    </BODY>
    </HTML>


    2.
    filename: nextPage.jsp
    code:
    <jsp:useBean id="userform" class="getname.UserData" scope="session"/>
    <HTML>
    <P>
    <P>
    <p>

    <BODY align="center">
    Hello,<BR>
    Your Name is: <jsp:getProperty name="userform" property="username" /><BR>
    Your Email is: <jsp:getProperty name="userform" property="email" /><BR>
    Your Age is: <jsp:getProperty name="userform" property="age" /><BR>

    <p>
    <p><A HREF="index.jsp">Next Record</>

    </BODY>
    </HTML>


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,550
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: Need Expect Help and Advice


  3. The Following User Says Thank You to Junky For This Useful Post:

    copeg (June 29th, 2011)

  4. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Need Expect Help and Advice

    Please do not post the same thing twice, and please keep the discussions in your other topic you started, and as you were advised in the other thread, use the code tags. I am locking this thread.

Similar Threads

  1. Need some serious advice
    By Rituparna in forum The Cafe
    Replies: 4
    Last Post: September 25th, 2013, 09:26 AM
  2. Some Simple Advice?
    By Diamond Fowl in forum AWT / Java Swing
    Replies: 2
    Last Post: April 30th, 2011, 10:36 PM
  3. need for some advice
    By kasiopi in forum AWT / Java Swing
    Replies: 6
    Last Post: January 26th, 2011, 10:34 AM
  4. A little advice please:
    By SDKC in forum Java Theory & Questions
    Replies: 1
    Last Post: December 8th, 2010, 08:15 PM
  5. i need some advice ....
    By mdstrauss in forum Java Theory & Questions
    Replies: 8
    Last Post: July 24th, 2009, 03:29 PM

Tags for this Thread