. Java Cart . Java Cart ItemGroupDBUtil java
Java Cart ItemGroupDBUtil java
package cart.dbUtils;
import cart.ItemSizeColor;
import cart.ItemBuilder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.ListIterator;
//ItemGroupDBUtil
//copyright - Lawrence Truett - FluffyCat.com
//date - August 11, 2003 - San Diego, CA
public class ItemGroupDBUtil {
public static long[] getItemsInGroup(long key, DBConnection dbc) {
try {
Connection connection = dbc.getConnection();
PreparedStatement preparedStatement =
connection.prepareStatement(
"Select * from itemGroup where groupKey = ?");
preparedStatement.setLong(1, key);
ResultSet resultSet = preparedStatement.executeQuery();
ArrayList arrayList = new ArrayList();
//unfortunately, you cant get the size of a result set, so
//we put it all into an ArrayList just to get it's size,
//and then we can define an int array and put all the data
//into that.
while (resultSet.next()) {
arrayList.add(new Long(resultSet.getLong(2)));
//group item
}
resultSet.close();
preparedStatement.close();
long[] longArrayToReturn = new long[arrayList.size()];
ListIterator listIterator = arrayList.listIterator();
int counter = 0;
while (listIterator.hasNext()) {
longArrayToReturn[counter++] =
((Long)listIterator.next()).longValue();
}
return longArrayToReturn;
} catch (java.sql.SQLException sqlException) {
System.out.println(
"The following error occured in "+
"ItemSizeColorDBUtil.getItemSizeColorForItemKey: " +
sqlException);
}
return null;
}
public static void insert(long groupKey,
long itemKey,
Connection connection) {
try {
PreparedStatement preparedStatement =
connection.prepareStatement(
"INSERT INTO itemGroup values(?,?);");
preparedStatement.setLong(1, groupKey);
preparedStatement.setLong(2, itemKey);
preparedStatement.execute();
preparedStatement.close();
} catch (java.sql.SQLException sqlException) {
System.out.println("The following error occured in "+
"ItemGroupDBUtil.insert: " +
sqlException);
}
}
}
download source, use right-click and "Save Target As..." to save with a .java extension.
| Comments |
| Sign In |
| to add the first comment for Java Cart ItemGroupDBUtil java. |