syidah mk

Greenhorn
+ Follow
since Feb 03, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by syidah mk

anybody there pls help .. need this to solve it by this week..
19 years ago
anybody there pls help .. need this to solve it by this week..
19 years ago

Originally posted by Yevgeniy Treyvus:
Have a look at this snippet...





i'm sorry guys.. i'm a slow learner but keen to know abt this.. i don't understand wat this means.. i'm using JSP.. so where do i put this codes??

i have this solution:
java.util.Date today = new java.util.Date();//creating date
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");//format definition
java.sql.Date curDate = java.sql.Date.valueOf(sdf.format(today));//creating SQL Date.

tried this solution but still get an error...
Syntax error converting datetime from character string.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

pls help ..
19 years ago
is SimpleDateFormat is a method in which we have to do it ourselves?
or just need to import it??
19 years ago
hi.. i need help in converting string to date.. i just need someone to check whether my code is correct or not..

here are my codes:


Date today = new Date();
DateFormat formatLong= DateFormat.getDateInstance(DateFormat.SHORT);
java.sql.Date curDate = java.sql.Date.valueOf(formatLong.format(today));

//and below is the storing part..

String query1 = null;
query1 = "Insert into ITS.dbo.orderDetails values(?)";

PreparedStatement stmnt = conn.prepareStatement(query1);


stmnt.setDate(1, curDate);

stmnt.executeUpdate();





anyone ..pls reply .. i need it urgently...
[ March 11, 2005: Message edited by: Bear Bibeault ]
19 years ago
hi.. i need help in converting string to date.. i just need someone to check whether my code is correct or not..

here are my codes:


Date today = new Date();
DateFormat formatLong= DateFormat.getDateInstance(DateFormat.SHORT);
java.sql.Date curDate = java.sql.Date.valueOf(formatLong.format(today));

//and below is the storing part..

String query1 = null;
query1 = "Insert into ITS.dbo.orderDetails values(?)";

PreparedStatement stmnt = conn.prepareStatement(query1);


stmnt.setDate(1, curDate);

stmnt.executeUpdate();





anyone ..pls reply .. i need it urgently...
hi..

i need help... is it possible to
display the error in the form using out.println rather than
alert message box when validating a form using javascript ???
19 years ago

Originally posted by Ben Souther:
If you put the code tags around your code, the indentation will be preserved and it will be much easier for us to read.

You're using the == operator to compare strings.
You should use the equals() method of String.
You were but you switched.



The '==' operator, when comparing object variables, will return true only if both variables point to the same object. Since you're using trim (which returns a new string) on your strings, it will always return false.



wow.. thanks you so much for helping me.. it works!!! frankly speaking, i'm not good in programming..hooray.. can party..
19 years ago
i'm using a vector.. and i thought if u use vector.. u need this enumeration loop??..

and this is a new code:

public void removeItem(String id){

Enumeration productEnum = getProducts();
System.out.println(productEnum);
while(productEnum.hasMoreElements()){
Product product = (Product)productEnum.nextElement();
String p = product.getId();
System.out.println("\n Inside removeItem(..) prodId , Id = " + p.trim() + ", "+ id);
System.out.println(productEnum);
if(p.trim()==id.trim()){
System.out.println("\n One match Found, Deleting it ");
products.removeElement(product);
System.out.println("Id = " + id);
System.out.println("product id = " + p.trim());
System.out.println(productEnum);
}
}
}

this works when i'm using sun one studio but when i used websphere.. it doesn't work.. so any of the experts know what's happening?? ..

what i found out is that it doesn't go to the if statement?? y??

and the output is like this:
19 years ago
and here are my new codes..

public void removeItem(String id){

System.out.println("Id = " + id);
for(Enumeration productEnum = getProducts();productEnum.hasMoreElements() {
Product product = (Product)productEnum.nextElement();
System.out.println("product id = " + product.getId());
if(id.equals(product.id)){
products.removeElement(product);
break;
}
}
}
19 years ago

Originally posted by Mark Vedder:
The code you show will always remove the first item. Your enumeration hits the first element, removes it, and then breaks out of the enumeration. Instead, you want to iterate through the enumeration and get the next product as you are doing, but only delete it if its id matches the id received as a parameter, and then break out of iterating through the enumeration (if the id doesn't match, you don't delete the current element, or break out of the enumeration; instead just loop through to the next element).

It should be noted that iterating through a shopping cart like that to remove an item is very inefficient. What type of collection (i.e. what class) are you using for your Shopping Cart? Take a look through the various collection classes in the Java API; you can learn about them via the Sun Tutorial on the Collection Framework. You should see a collection type that is geared towards this type of thing, and will allow you to add and remove items in a very efficient manner, without needing to iterate through them.



thanks for the reply.. the code works.. but when i used sun 1 microsystem .. but now i have to used websphere.. and this problem faced.. and i dunno wat to do...
19 years ago
hi all.. i need ur help to check what's wrong with my codes..

e.g.
item 1 Remove btn
item 2 Remove btn
item 3 Remove btn

when i click on the Remove btn of item 2 in shopping cart page.. it removes the item 1.. y???

below are the codes:


public void removeItem(String id){
Enumeration productEnum = getProducts();
while(productEnum.hasMoreElements()){
Product product = (Product)productEnum.nextElement();
products.removeElement(product);



break;

}
}






pls i desperately need someone.. to help me .. :<
19 years ago
hi.. i'm an amatuer student who just learnt abt JSP.. i was given a project tot do shopping cart.. and it's due soon.. i need help regarding my codes.. i try so many methods but it doesn't work.. there is problem with my remove item.. when i try to remove an item.. it does not remove the item.. can somebody help me with my codes.. is there something wrong with my JavaBeans??

i have 2 javafiles..

Product.java


package product;

public class Product {
String id, name, size, colour, other;
int quantity;
double price, total;

public Product(String newid, String newname, String newsize, String newcolour, String newother, double newprice, int newqty)
//public Product(String newid, String newname, double newprice)

{
id= newid;
name= newname;
size= newsize;
colour= newcolour;
other = newother;
price = newprice;
quantity= newqty;
}

public String getId()
{
return id;
}

public String getName()
{
return name;
}

public String getSize()
{
return size;
}

public String getColour()
{
return colour;
}

public String getOther()
{
return other;
}

public int getQuantity()
{
return quantity;
}

public double getPrice()
{
return price;
}

public double getTotal()
{
return (price*quantity);
}
}



ShoppingCart .java

package product;
import java.util.*;

public class ShoppingCart {
int noItems = 0;
Vector products = new Vector();

public void addProduct(Product i){
products.addElement(i);
}

public void deleteProduct(String id){
Enumeration productEnum = getProducts();
while(productEnum.hasMoreElements()){
Product product = (Product)productEnum.nextElement();
if(product.getId().equals(id)){
//products.removeElement(id);
products.removeElement(product.id);
break;
}
}
}

public void emptyCart(){
products.clear();

}

public int getNoProducts(){
return products.size();
}

public Enumeration getProducts(){
return products.elements();

}

public double getTotal(){
Enumeration productEnum = getProducts();
double total=0;

while(productEnum.hasMoreElements()){
Product product = (Product)productEnum.nextElement();
total = total + product.getTotal();
}
return total;
}

}




viewsc1.jsp


<%@page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>viewsc1.jsp</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="sCart" class="product.ShoppingCart" scope="session"/>
<%@page import="product.Product"%>


<table width="80%" border="0" align="center">
<tr>
<td align="center"><img src="image/title.jpg" width="450" height="80"></td>
</tr>
<tr>
<td align="center" height="90"> </td>
</tr>
<tr>
<td align="center" height="210">

<table width="98%" border="1" height="142">
<tr>
<td height="129">
<table border="0" width="100%">
<tr>
<td colspan="9" bgcolor="#CCCC99" align="center" height="22">
<img src="image/vsc.jpg" width="300" height="50">
</td>
</tr>
<tr>
<td height="15" colspan="9"></td>
</tr>



<%
String name= request.getParameter("name");
if(name!= null){
if(name.equals("Empty")){
sCart.emptyCart();
%>
<SCRIPT>
alert("Your Shopping Cart is empty.");
location.href="chooseCategory.jsp";
</SCRIPT>
<%}else if(name.equals("delete")){
String index = request.getParameter("Id");
sCart.removeItem(index);
out.println(index);

}else if (name.equals("update")){
String[] prodQtys = request.getParameterValues("newQty");
// sCart.updateQtys(prodQtys);
}
}


if(sCart.getNoProducts()!=0){%>

<tr>
<td height="15" align="center" width="20%"><B>Item ID</B></td>
<td height="15" align="center" width="20%"><B>Item Name</B></td>
<td height="15" align="center" width="11%"><b>Size</b></td>
<td height="15" align="center" width="9%"><B>Colour</b></td>
<td height="15" align="center" width="13%"><b>Price</b></td>
<td height="15" align="center" width="10%"><b>Qty</b></td>
<td height="15" align="center" width="12%"></td>
<td height="15" align="center" width="12%"><b>Total:</b></td>
<td height="15" align="center" width="12%"></td>
</tr>

<%//<FORM action="viewsc1.jsp?name=update" method=POST>
Enumeration products =sCart.getProducts();
while(products.hasMoreElements()){
Product product = (Product)products.nextElement();
if(product.getQuantity()!=0){
%>

<tr>
<td height="15" align="center" width="20%"><B><%=product.getId() %></B></td>
<td height="15" align="center" width="11%"><b><%=product.getName() %></b></td>
<td height="15" align="center" width="9%"><B><%=product.getSize() %></b></td>
<td height="15" align="center" width="9%"><B><%=product.getColour() %></b></td>
<td height="15" align="center" width="13%"><b><%=product.getPrice() %></b></td>
<td height="15" align="center" width="9%"><input type=text name="newQty" value="<%=product.getQuantity()%>">
<a href="editQty.jsp?id=<%=product.getId() %>&name=<%=product.getName() %>&qty=<%=product.getQuantity()%>">Edit</a>
</td>
<td height="15" align="center" width="9%"><B><%=product.getOther() %></b></td>
<td height="15" align="center" width="10%"><b><%=product.getTotal() %></b></td>
<td align='center'><a href="viewsc1.jsp?name=delete&Id=<%=product.getId() %>">Remove</a></td>
</tr>

<%}else{ %>
<tr>
<td height="15" align="center" width="20%"><B><%=product.getId() %></B></td>
<td height="15" align="center" width="11%"><b><%=product.getName() %></b></td>
<td height="15" align="center" width="9%"><B><%=product.getSize() %></b></td>
<td height="15" align="center" width="9%"><B><%=product.getColour() %></b></td>
<td height="15" align="center" width="13%"><b><%=product.getPrice() %></b></td>
<td height="15" align="center" width="9%"><B><%=product.getQuantity() %></b></td>
<td height="15" align="center" width="9%"><B><%=product.getOther() %></b></td>
<td height="15" align="center" width="10%"><b><%=product.getTotal() %></b></td>
<td align='center'><a href="viewsc1.jsp?name=delete&Id=<%=product.getId() %>">Remove</a></td>
</tr>
<%}

} %>

<tr>
<td height="50" valign="bottom" colspan="9" height="15" align="right" width="12%"><b>Total:</b><%=sCart.getTotal() %></td>
</tr>

<%
}else{%>
<SCRIPT>
alert("Your Shopping Cart is empty.");
location.href="chooseCategory.jsp";
</SCRIPT>
<%}
%>
<tr>
<td colspan="9" height="15" align="center">
<input type=submit value='Update Quantity'>
<a href=chooseCategory.jsp><IMG border="0" src="image/BtnContinueshop.gif" width="153" height="27"></a>
<a href="viewsc1.jsp?name=Empty"><IMG border="0" src="image/BtnEmptyBsk.gif" width="75" height="27"> </a>
<a href=checkout.jsp><IMG border="0" src="image/BtnCheckOut.gif" width="156" height="27"></a>
</td>
</tr>
</form>
</table>

</BODY>
</HTML>
[ February 03, 2005: Message edited by: Bear Bibeault ]
19 years ago
JSP