Results 1 to 2 of 2
  1. #1
    nash1990 is offline Member
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Exclamation Not able to data into database

    hey frnz please help me it;s urgent..
    i am not able to insert data into mysql. i used a form to accept values then set action to that jsp file..now that file gets oepend in the browser correctly without any error..but he data is not inserted..please help me...i am posting the code also

    insert_company.html

    <!--
    To change this template, choose Tools | Templates
    and open the template in the editor.
    -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Insert New Company-Sure Vac Technologies</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
    <form action="insert_company.jsp" method="post" name="company">
    <table width="300" border="0" cellspacing="5">
    <tr>
    <td>Company ID:</td>
    <td><input name="cmp_id" type="text" maxlength="11" /></td>
    </tr>
    <tr>
    <td>Company Name:</td>
    <td><input name="name" type="text" maxlength="50" /></td>
    </tr>
    <tr>
    <td>Address:</td>
    <td><input name="address" type="text" maxlength="80" /></td>
    </tr>
    <tr>
    <td>Contact Number:</td>
    <td><input name="contact" type="text" maxlength="11" /></td>
    </tr>
    <tr>
    <td><input name="submit" type="submit" value="SUBMIT" /></td>
    <td><input name="reset" type="reset" value="RESET" /></td>
    </table>

    </form>
    </body>
    </html>


    insert_company.jsp
    <%--
    Document : Syphha Web Solutions
    Created on : Aug 11, 2010, 1:00:36 AM
    Author : nash
    --%>

    <%@page contentType="text/html" import="java.sql.*,java.lang.*,java.util.*,java.io .*;" pageEncoding="UTF-8"%>
    <%
    try
    {
    Integer id = Integer.parseInt(request.getParameter("cmp_id"));
    String name=request.getParameter("name");
    String address=request.getParameter("address");
    Integer contact=Integer.parseInt(request.getParameter("con tact"));
    String connectionURL = "jdbc:mysql://localhost:3306/sure_vac";
    Class.forName("com.mysql.jdbc.Driver");
    Connection connection=DriverManager.getConnection(connectionU RL, "root", "");
    if(connection.isClosed())
    {
    out.println("error");
    }
    else
    {
    PreparedStatement statement=connection.prepareStatement("Insert into company values(?,?,?,?)");
    statement.setInt(1,id);
    statement.setString(2,name);
    statement.setString(3,address);
    statement.setInt(4,contact);
    statement.execute();
    out.println("success");
    }
    }
    catch(Exception e)
    {
    System.out.println("Error:"+ e.getMessage());
    }
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">




    please help as it is urgent

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Who knows?
    If this were a servlet I'd suggest debugging through it to see what's going on, but since you've stuck business code in your JSP (which is not what a JSP is for) then I'm not sure how easy that will be.

    And you should use code tags when posting code, to retain formatting.

Similar Threads

  1. why i can't insert data to database
    By khaa_khay in forum Web Frameworks
    Replies: 0
    Last Post: 05-26-2010, 05:37 AM
  2. data between dates in database.
    By mkkrkiran in forum New To Java
    Replies: 1
    Last Post: 09-22-2009, 10:02 AM
  3. [SOLVED] Getting Data from a database
    By AJG in forum New To Java
    Replies: 8
    Last Post: 04-04-2008, 12:52 PM
  4. Replies: 0
    Last Post: 03-11-2008, 04:55 PM
  5. How to query data from database using SSL
    By mano in forum New To Java
    Replies: 0
    Last Post: 08-02-2007, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •