-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Not submitted data in a combo box to the database
PostPosted: Mon Mar 29, 2004 5:51 am 
Beginner
Beginner

Joined: Wed Mar 24, 2004 8:43 am
Posts: 42
hi


i have jsp form, it includes two combo boxes. the values of the combo boxes are filled using sql query( From another tables) It is working successfully,but the problem is, when i going to submit the above form , the error occurs.

i used hibernate 2.1/mysql

errors

14:50:56,543 WARN JDBCExceptionReporter:38 - SQL Error: 1048, SQLState: S1000
14:50:56,543 ERROR JDBCExceptionReporter:46 - General error: Column 'order_id' c
annot be null
14:50:56,543 WARN JDBCExceptionReporter:38 - SQL Error: 1048, SQLState: S1000
14:50:56,559 ERROR JDBCExceptionReporter:46 - General error: Column 'order_id' c
annot be null
14:50:56,559 ERROR JDBCExceptionReporter:38 - Could not execute JDBC batch updat
e
java.sql.BatchUpdateException: General error: Column 'order_id' cannot be null

here is the database
CREATE TABLE ORDERS(
ID VARCHAR NOT NULL PRIMARY KEY,
ORDER_DATE TIMESTAMP NOT NULL,
PRICE_TOTAL DOUBLE NOT NULL)

CREATE TABLE PRODUCTS(
ID VARCHAR NOT NULL PRIMARY KEY,
NAME VARCHAR NOT NULL,
PRICE DOUBLE NOT NULL,
AMOUNT INTEGER NOT NULL)

CREATE TABLE ORDER_ITEMS(
ID VARCHAR NOT NULL PRIMARY KEY,
ORDER_ID VARCHAR NOT NULL,
PRODUCT_ID VARCHAR NOT NULL,
AMOUNT INTEGER NOT NULL,
PRICE DOUBLE NOT NULL.)

here i am going to insert the data into ORDER_ITEMS table

here is the jsp form

<html>
<head>
<title>Product List</title>
</head>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<body>
<form method="POST" action="orderitemevent.action">
<h1> Order Items </h1>
<%
test.hibernate.actions.GetProductName e=new test.hibernate.actions.GetProductName();
String s=e.doExecute();
java.util.List list=e.getProducts();
Iterator iter = list.iterator();
test.hibernate.actions.GetOrderName g=new test.hibernate.actions.GetOrderName();
String d=g.doExecute();
java.util.List list1=g.getProducts();
Iterator iter1 = list1.iterator();
%>

<table>
<tr>
<td><b>Product Name</b></td><td><select name="productname">
<%
while (iter.hasNext()) {
test.hibernate.data.Product p = (test.hibernate.data.Product) iter.next();
String c=p.getId();
String a= p.getName();
double b=p.getPrice();
%>
<option value='<%=c%>'><%=a%></option>
<%
}
%>
</select> </td>
</tr>
<tr>
<td><b>Order Name</b></td><td><select name="ordername">
<%
while (iter1.hasNext()) {
test.hibernate.data.Order o = (test.hibernate.data.Order) iter1.next();
String f=o.getId();
String h=o.getOname();
%>
<option value='<%=f%>'><%=h%></option>
<%
}
%>
</select> </td>
</tr>
<tr>
<td><b>amount</b></td>
<td><input type="text" name="amount" /></td>
</tr>
<td><b>price</b></td>
<td><input type="text" name="price" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit"/></td>
</tr>
</table>
</body>
</html>


here is the (action) java class orderitemevent.action

package test.hibernate.actions;

import java.util.List;
import java.util.Date;
import java.text.DateFormat;


import webwork.action.ActionSupport;
import webwork.action.CommandDriven;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.HibernateException;
import test.hibernate.util.SessionManager;
import test.hibernate.data.Order;
import test.hibernate.data.OrderItem;
import test.hibernate.data.Product;

public class NewOrderItems extends ActionSupport implements CommandDriven {
private String oname;
private String pname;
private int amount;
private double priceTotal;

public String getOrdername() {
return oname;
}
public void setOrdername(String oname) {
this.oname = oname;
}
public String getProductname() {
return pname;
}
public void setProductname(String pname) {
this.pname = pname;
}
public double getPrice() {
return priceTotal;
}

public void setPrice(double priceTotal) {
this.priceTotal = priceTotal;
}

public int getAmount() {
return amount;
}

public void setAmount(int amount) {

this.amount=amount;
}
public String doExecute() {
try {
Configuration cfg=new Configuration().addClass(OrderItem.class).addClass(Order.class).addClass(Product.class);
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
OrderItem event = new OrderItem();
event.setOrderId(oname);
event.setProductId(pname);
event.setAmount(amount);
event.setPrice(priceTotal);
sess.save(event);
sess.flush();
System.out.println("hei sucess");
return SUCCESS;
} catch (HibernateException e) {
e.printStackTrace();
System.out.println("hei error");
return ERROR;
}
}

public String doEnter() {
return INPUT;
}

}


here is the OrderItem class(Like Bean class)

package test.hibernate.data;

public class OrderItem {
public OrderItem() {
// empty default constructor
}


private String id;
private Product product;
private Order order;
private String productId;
private String orderId;
private double price;
private int amount;

public int getAmount() {
return amount;
}
public String getId() {
return id;
}
public Order getOrder() {
return order;
}
public String getOrderId() {
return orderId;
}
public double getPrice() {
return price;
}
public Product getProduct() {
return product;
}
public String getProductId() {
return productId;
}
public void setAmount(int i) {
amount = i;
}
public void setId(String string) {
id = string;
}
public void setOrder(Order order) {
this.order = order;
}
public void setOrderId(String string) {
this.orderId = string;
}
public void setPrice(double d) {
price = d;
}
public void setProduct(Product product) {
this.product = product;
}
public void setProductId(String string) {
this.productId = string;
}

}


here is property file

orderitemevent.action=NewOrderItems
orderitemevent.input=/WEB-INF/views/orderItemForm.jsp
orderitemevent.success=index.html
orderitemevent.enter.action=NewOrderItems!enter

pls help regards
gimhan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.