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

Thread: Needs experts help and advice

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

    Default Needs experts 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 Code:
    <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 db="saveData";
         String url = "jdbc:odbc:saveData";
         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,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Needs experts help and advice

    Unformatted code - CHECK
    Lots of it - CHECK
    No explanation of what the problem is - CHECK
    Very low chance that someone will bother - CHECK

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Needs experts help and advice

    I have added code tags for you this time..

    Have you confirmed that you have connected to the database correctly?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Needs experts help and advice

    I recommend reading how to use statement and how to use PreparedStatements
    Processing SQL Statements with JDBC (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics)
    Using Prepared Statements (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics)

Similar Threads

  1. Replies: 1
    Last Post: March 17th, 2011, 04:12 AM
  2. hi my dear experts
    By khamis50 in forum Object Oriented Programming
    Replies: 2
    Last Post: March 1st, 2011, 09:57 AM
  3. hello java experts
    By bidex in forum Member Introductions
    Replies: 2
    Last Post: August 23rd, 2010, 05:52 AM
  4. Question for Java experts please
    By XElCaballoX in forum Java Theory & Questions
    Replies: 2
    Last Post: August 19th, 2010, 01:43 AM