leonidassavvides
02-01-2010, 10:55 AM
well can you tell how transfer a List eg. created as
public List getLineList() { // beans.OrderTotals
return lineList;
}
public static void addPlant(OrderPlantItem orderPlantItem) {
lineList.add( orderPlantItem );
}
from bean to jsp or from bean to bean or from jsp call to bean, and appear contents on screen-jsp(view) or populate a Table(db) ?
In a Shopping cart web app I must add lineItems first and after Order, to Tables in DB: LineItems and Orders respectively?
//beans.AddOrder
........
public String updateTables(OrderTotals OrderTotals2, List lineList2) { // void
String sqlCommand1= "INSERT INTO Customers VALUES('0011','"+this.getCustName()+"','"+this.getCustStreet()+"','"+this.getCustCity()+"','"+this.getCustState()+"','"+this.getCustZip()+"','2')" ;
String sqlCommand2= "INSERT INTO Orders VALUES('1011','0011','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+OrderTotals2.getShipping()+","+OrderTotals2.getTax()+")" ;
String url = "jdbc:odbc:plants"; //dsn plants
String user="";
String password="";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection
("jdbc:odbc:plants", user, password);
sttmnt=conn.createStatement();
sttmnt1=conn.createStatement();
sttmnt2=conn.createStatement();
//get statement object
}catch (Exception exception) {
//return (exception.getMessage());
} // end of catch
finally {
//
}
try {
sttmnt.executeUpdate(sqlCommand1);
//Object[] lineList2 = lineList5.toArray();
for (int i = 0; i < lineList2.size(); i++) //lineList2.length
{
OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i);
String sqlCommand3= "INSERT INTO OrderDetail VALUES('1011',"+i+1+","+lineItem0.getPlantID()+","+lineItem0.getQty()+","+lineItem0.getSubtotal()+")" ;
sttmnt2.executeUpdate(sqlCommand3);
}
sttmnt1.executeUpdate(sqlCommand2);
} // end of try
catch
<jsp:useBean id="add" scope="session" class="beans.AddOrder" />
<jsp:useBean id="AddChoosePlant" scope="session" class="beans.OrderTotals" />
<%
add.updateTables(AddChoosePlant,AddChoosePlant.getLineList());
%>
public List getLineList() { // beans.OrderTotals
return lineList;
}
public static void addPlant(OrderPlantItem orderPlantItem) {
lineList.add( orderPlantItem );
}
from bean to jsp or from bean to bean or from jsp call to bean, and appear contents on screen-jsp(view) or populate a Table(db) ?
In a Shopping cart web app I must add lineItems first and after Order, to Tables in DB: LineItems and Orders respectively?
//beans.AddOrder
........
public String updateTables(OrderTotals OrderTotals2, List lineList2) { // void
String sqlCommand1= "INSERT INTO Customers VALUES('0011','"+this.getCustName()+"','"+this.getCustStreet()+"','"+this.getCustCity()+"','"+this.getCustState()+"','"+this.getCustZip()+"','2')" ;
String sqlCommand2= "INSERT INTO Orders VALUES('1011','0011','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+OrderTotals2.getShipping()+","+OrderTotals2.getTax()+")" ;
String url = "jdbc:odbc:plants"; //dsn plants
String user="";
String password="";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection
("jdbc:odbc:plants", user, password);
sttmnt=conn.createStatement();
sttmnt1=conn.createStatement();
sttmnt2=conn.createStatement();
//get statement object
}catch (Exception exception) {
//return (exception.getMessage());
} // end of catch
finally {
//
}
try {
sttmnt.executeUpdate(sqlCommand1);
//Object[] lineList2 = lineList5.toArray();
for (int i = 0; i < lineList2.size(); i++) //lineList2.length
{
OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i);
String sqlCommand3= "INSERT INTO OrderDetail VALUES('1011',"+i+1+","+lineItem0.getPlantID()+","+lineItem0.getQty()+","+lineItem0.getSubtotal()+")" ;
sttmnt2.executeUpdate(sqlCommand3);
}
sttmnt1.executeUpdate(sqlCommand2);
} // end of try
catch
<jsp:useBean id="add" scope="session" class="beans.AddOrder" />
<jsp:useBean id="AddChoosePlant" scope="session" class="beans.OrderTotals" />
<%
add.updateTables(AddChoosePlant,AddChoosePlant.getLineList());
%>