Results 1 to 3 of 3
- 04-01-2012, 06:26 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 1
- Rep Power
- 0
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>
- 04-01-2012, 06:29 AM #2
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-02-2012, 10:54 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
Similar Threads
-
Inserting Data in database
By Marty Jones in forum NetBeansReplies: 3Last Post: 01-03-2012, 12:33 PM -
Inserting Data in database
By Marty Jones in forum JDBCReplies: 2Last Post: 12-31-2011, 01:55 PM -
data is not inserting into database
By gb.rashu in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 08-21-2010, 03:05 PM -
Problem regarding Inserting data into Mysql via JSP
By abhi118 in forum JDBCReplies: 5Last Post: 04-05-2010, 01:24 PM -
Problem inserting values to MySQL tables from the Data Source Explorer
By tip in forum EclipseReplies: 0Last Post: 12-24-2007, 09:47 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks