Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2006, 07:06 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Im trying to insert data into mysql using jsp

Can you advice me on my code, im new to this- im trying to insert data into mysql using a jsp form.. Am i doing this correctly. any help, much appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>REGISTRATION</title>
</head>

<html>
    <body>
        <form action="Registration.jsp" method=post>

        <center>
        <table cellpadding=4 cellspacing=2 border=0>
        <th bgcolor="#CCCCFF" colspan=2>
        USER REGISTRATION
        <br></th>
        <tr bgcolor="#c8d8f8">
        <td valign=top>

        <b>First Name</b><br>
        <input type="text" name="firstName" value="" size=15 maxlength=20></td>
        <td valign=top>

        <b>Last Name</b><br>
        <input type="text" name="lastName" value="" size=15 maxlength=20></td>
        </tr>
        <tr bgcolor="#c8d8f8">
        <td valign=top>

        <b>E-Mail</b><br>
        <input type="text" name="email" value="" size=25 maxlength=125>
        <br></td>
        <td valign=top>

        <b>Date of Birth </b><br>
        <input type="text" name="dateOfBirth" value="" size=15 maxlength=5></td>
        </tr>
        <tr bgcolor="#c8d8f8">
        <td valign=top colspan=2>
        <div align="center">

        <b>Desired User Name</b><br>
              <input type="text" name="userName" size=30 value="" maxlength=10>
          </div></td>
        </tr>
        <tr bgcolor="#c8d8f8">
        <td valign=top>

        <b>Password</b><br>
        <input type="password" name="password" size=10 value=""
        maxlength=10></td>
        <td valign=top>

        <b>Confirm Password</b><br>
        <input type="password" name="password2" size=10 value=""
        maxlength=10></td>
        <br>
        </tr>
        <tr bgcolor="#c8d8f8">
        <td valign=top colspan=2>
        <div align="center">

        <b>Gender</b>
        <br>
          <input type="radio" name="notify" value="Yes" checked>
        Male
        <input type="radio" name="notify" value="No" >
        Female
        <br>
        <br>
        </div></td>
        </tr>
        <tr bgcolor="#c8d8f8">
        <td align=center colspan=2>

        <input type="submit" value="Submit"> <input type="reset"
        value="Reset">
        </td>
        </tr>

        </table>
        </center>
    </form>

////////////////////////////////jsp code
<%
        Connection conn = null;
    String username= "lovers";
        String password= "project";
    String url= "jdbc:mysql://csserver.ucd.ie/lovers";


    String userName1 = request.getParameter("userName");
        String password1 = request.getParameter("password");
    String eaddress = request.getParameter("email");
        String dob = request.getParameter("dateOfBirth");
        String ************ = request.getParameter("notify");


        try{
            Class.forName("com.mysql.jdbc.Driver").newInstance ();
            conn = DriverManager.getConnection (url, userName, password);

            java.sql.Date age= java.sql.Date.valueOf(dob);

            PreparedStatment st;
            st = conn.prepareStatement("INSERT INTO REGISTRATION (USERID, USERNAME, PASSWORD, EMAIL, DATEOFBIRTH, ************) VALUES (?,?,?,?,?,?)");

                 st.setInt(1,0);
                 st.setString(2,userName1);
                 st.setString(3,password);
                 st.setString(4,eaddress);
                 st.setDate(5,age);
                 st.setInt(6,************);


        st.executeUpdate();
                st.clearParameters();


        conn.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }


%>

</body>
</html>


 
Old September 12th, 2006, 02:35 AM
Registered User
 
Join Date: Sep 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sharad_iips2003 Send a message via Yahoo to sharad_iips2003
Default

I am also getting a similar problem while inserting into a student table in database iips. If you now have the solution , please help....I would be very thankful to you...






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to insert datatable data in mysql with dnn rizwanrizi SQL Server ASP 0 August 26th, 2008 05:36 AM
PHP-MySQL Insert Data problem forexen PHP Databases 1 March 13th, 2007 12:58 AM
JSP-n-MySQL anshul JSP Basics 0 May 31st, 2005 02:21 AM
cannot insert into mysql:data LogicalDevloper Pro PHP 1 December 22nd, 2004 09:08 AM
Data Shaping Problem .. im stuck! jeuriks SQL Server ASP 2 March 19th, 2004 11:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.