Results 1 to 3 of 3
  1. #1
    mblopez89 is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default Problem with inserting data into MYSQL database

    Hello, I am trying to insert three values into a table via a jsp page. However, when I input text into the boxes, the information is not inserted into my database. Any tips would be greatly appreciated! Here is my code:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <jsp:useBean id="utils" class="utils.insertBean" scope="session" />
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert Parts</title>
    </head>
    <body>

    <center><h1>Insert Parts into Inventory</h1></center>
    <form action="insert.jsp" METHOD="post">
    Part Name: <input type="text" name="partName" /><br />
    Color: <input type="text" name="partColor" /><br />
    Price <input type="text" name="partPrice" /><br />
    <input type="submit" value="Insert" />
    </form>

    <%
    String connectionURL = "jdbc:mysql://localhost:3306/spaceport";
    Connection connection = null;

    Class.forName("com.mysql.jdbc.Driver").newInstance ();

    connection = DriverManager.getConnection(connectionURL, "root", "");
    Statement statement = connection.createStatement();

    if(request.getParameter("action") != null){
    String partName = request.getParameter("partName");
    String partColor = request.getParameter("partColor");
    String partPrice = request.getParameter("partPrice");

    statement.execute("INSERT INTO `spaceport`.`shippart` (`PKShipPartID`, `Name`, `Color`, `Price`) VALUES (``,`"+partName+"`, `"+partColor+"`,`"+partPrice+"`)");
    }


    %>
    </font>

    </body>
    </html>

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Problem with inserting data into MYSQL database

    Look around the FAQs of the site and discover how to post code so that it retains its formatting.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Problem with inserting data into MYSQL database

    And after you've done that then rewrite your JSP into a servlet, since that sort of data access and manipulation should not be done in a JSP, which is intended for displaying stuff.
    Indeed, that code should be in a data layer called by the servlet.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Inserting Data in database
    By Marty Jones in forum NetBeans
    Replies: 3
    Last Post: 01-03-2012, 12:33 PM
  2. Inserting Data in database
    By Marty Jones in forum JDBC
    Replies: 2
    Last Post: 12-31-2011, 01:55 PM
  3. data is not inserting into database
    By gb.rashu in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 08-21-2010, 03:05 PM
  4. Replies: 5
    Last Post: 04-05-2010, 01:24 PM
  5. Replies: 0
    Last Post: 12-24-2007, 09:47 AM

Posting Permissions

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