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

    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"
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <%@ page import="java.sql.*" %>
    <%@ page import="*" %>
    <jsp:useBean id="utils" class="utils.insertBean" scope="session" />
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert Parts</title>

    <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" />

    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+"`)");



  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    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.

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

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Rep Power

    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, 01:33 PM
  2. Inserting Data in database
    By Marty Jones in forum JDBC
    Replies: 2
    Last Post: 12-31-2011, 02: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, 04:05 PM
  4. Replies: 5
    Last Post: 04-05-2010, 02:24 PM
  5. Replies: 0
    Last Post: 12-24-2007, 10: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