this is my product screen i suppose to add product into the database db2 but when i insert to database it give me error (null for supplier id) please help me
this is my screen.
<%@ page contentType="text/html; charset=" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>AddProduct</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="http://localhost:8080/Inventory/ap">
<table width="100%" border="0">
<tr>
<td height="77" colspan="4"> <div align="center"><font size="6" face="Verdana, Arial, Helvetica, sans-serif"><strong>Product</strong></font></div></td>
</tr>
<tr>
<td width="18%"> </td>
<td width="31%"> </td>
<td width="12%"><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font></div></td>
<td width="39%"> </td>
</tr>
<tr>
<td> <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Product ID </label>
</font></div></td>
<td> <input name="prodID_f" size="20"></td>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Category</label>
</font></div></td>
<td><select name="select">
</select> </td>
</tr>
<tr>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Barcode </label>
</font></div></td>
<td><input name="prodCode_f" size="20"></td>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Qty On Hand </label>
</font></div></td>
<td><input name="prodQty_f" size="20"></td>
</tr>
<tr>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Desc </label>
</font></div></td>
<td><input name="prodDesc_f" size="30"></td>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Order Level </label>
</font></div></td>
<td><input name="prodLevel_f" size="20"></td>
</tr>
<tr>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Price </label>
</font></div></td>
<td><input name="prodPrice_f" size="20"></td>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Supplier </label>
</font></div></td>
<td><select name="supp_f">
</select></td>
</tr>
<tr>
<td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>GST </label>
</font></div></td>
<td><input name="prodGST_f" size="20"></td>
<td> <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<label>Dept </label>
</font></div></td>
<td><select name="select2">
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> <input type="submit" name="prodSubmit" value=" Add "></td>
<td> </td>
<td><div align="right"></div></td>
</tr>
</table>
</form>
</body>
</html>
this is my product entity
package inventory.inv_Bean;
public class Product_entity
{
private int prodID;
private int barcode;
private String desc;
private double regPrice;
private double gst;
private double qoh;
private int orderLevel;
private int orderQuantity;
public Product_entity(int prodID,int barcode, String desc, int orderQuantity)
{
this.prodID= prodID;
this.barcode = barcode;
this.desc = desc;
this.orderQuantity = orderQuantity;
}
public Product_entity(int prodID, int barcode, String desc, double regPrice, double gst,
double qoh, int orderLevel, int orderQuantity)
{
setProdID(prodID);
setBarcode(barcode);
setDesc(desc);
setRegPrice(regPrice);
setGst(gst);
setQoh(qoh);
setOrderLevel(orderLevel);
setOrderQuantity(orderQuantity);
}
public void setProdID(int prodID) {
this.prodID= prodID;
}
public int getProdID() {
return prodID;
}
public void setBarcode(int barcode) {
this.barcode = barcode;
}
public int getBarcode() {
return barcode;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
public void setRegPrice(double regPrice) {
this.regPrice = regPrice;
}
public double getRegPrice() {
return regPrice;
}
public void setGst(double gst) {
this.gst = gst;
}
public double getGst() {
return gst;
}
public void setQoh(double qoh) {
this.qoh = qoh;
}
public double getQoh() {
return qoh;
}
public void setOrderLevel(int orderLevel) {
this.orderLevel = orderLevel;
}
public int getOrderLevel() {
return orderLevel;
}
public void setOrderQuantity(int orderQuantity){
this.orderQuantity = orderQuantity;
}
public int getOrderQuantity(){
return orderQuantity;
}
}
this is my servlet
package inventory.servlet;
// AddProductServlet.java
// Servlet for adding product to the database. Web-based database access.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import inventory.inv_Bean.*;
public class AddProServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html";
//boolean success;
PrintWriter output;
Inv_DBQuery db;
Product_entity product;
public void init() throws ServletException
{
}
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
output = res.getWriter();
int id = Integer.parseInt(req.getParameter("prodID_f"));
int code = Integer.parseInt(req.getParameter("prodCode_f"));
String desc = req.getParameter("prodDesc_f");
double regPrice =Double.parseDouble( req.getParameter("prodPrice_f"));
double gst =Double.parseDouble(req.getParameter("prodGST_f"));
double qtyHand = Double.parseDouble(req.getParameter("prodQty_f"));
int level = Integer.parseInt(req.getParameter("prodLevel_f"));
int orderQty = Integer.parseInt(req.getParameter(""));
res.setContentType("text/html");
// System.out.println("OK1");
/* if (desc.equals(""))
{
res.setContentType(CONTENT_TYPE);
output.println("<h3>Please click the back button and fill in" +
" all required fields.</h3>");
output.close();
}
else
{ */
product = new Product_entity(id, code, desc, regPrice, gst, qtyHand, level, orderQty);
db = new Inv_DBQuery();
db.addProduct(product);
System.out.println("product OK");
output.close();
}
}
by: vikram_1982Posted on 2004-05-27 at 00:55:57ID: 11169212
You, obviously arent passing any value to the supplierid field in the database. Which is the input field that u pass to the supplier id column in the database?