package cart.dbUtils; import cart.ItemSizeColor; import cart.ItemBuilder; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLOutput; import java.util.ArrayList; //ItemSizeColorDBUtil //copyright - Lawrence Truett - FluffyCat.com //date - August 4, 2003 - San Diego, CA public class ItemSizeColorDBUtil { public static ItemSizeColor getItemSizeColorForItemKey( long key, DBConnection dbc) { ItemSizeColor ItemSizeColorToReturn = null; try { Connection connection = dbc.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement( "Select * from itemSizeColor where itemKey = ?"); preparedStatement.setLong(1, key); ResultSet resultSet = preparedStatement.executeQuery(); resultSet.first(); ItemSizeColorToReturn = new ItemSizeColor(resultSet.getLong(1), resultSet.getString(2), //size resultSet.getString(3)); //color resultSet.close(); preparedStatement.close(); } catch (java.sql.SQLException sqlException) { System.out.println("The following error occured in "+ "ItemSizeColorDBUtil.getItemSizeColorForItemKey: " + sqlException); } return ItemSizeColorToReturn; } public static ArrayList getAllItemSizeColors(DBConnection dbc) { ArrayList ItemSizeColorsToReturn = new ArrayList(); try { Connection connection = dbc.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("Select * from itemSizeColor"); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { ItemSizeColorsToReturn.add( new ItemSizeColor(resultSet.getLong(1), resultSet.getString(2), //size resultSet.getString(3)));//color } resultSet.close(); preparedStatement.close(); } catch (java.sql.SQLException sqlException) { System.out.println("The following error occured in "+ "ItemSizeColorDBUtil.getAllItemSizeColors: " + sqlException); } return ItemSizeColorsToReturn; } public static void insert(long itemKey, String size, String color, Connection connection) { try { PreparedStatement preparedStatement = connection.prepareStatement( "INSERT INTO itemSizeColor values(?,?,?);"); preparedStatement.setLong(1, itemKey); preparedStatement.setString(2, size); preparedStatement.setString(3, color); boolean insertOk = (preparedStatement.execute()); //!insertOk on good insert, what gives??? if (!insertOk) { java.sql.SQLWarning sqlWarning = preparedStatement.getWarnings(); System.out.println("INSERT INTO ItemSizeColor - "+ "SQLWarning: " + sqlWarning); } preparedStatement.close(); } catch (java.sql.SQLException sqlException) { System.out.println("The following error occured in "+ "ItemSizeColorDBUtil.insert: " + sqlException); } } }