1 25 26 29 package net.killingar.forum.internal.managers; 30 31 import java.sql.Connection ; 32 import java.sql.PreparedStatement ; 33 import java.sql.ResultSet ; 34 import java.sql.SQLException ; 35 36 public final class ItemListManager extends AbstractManager implements java.io.Serializable 37 { 38 41 public void addItem(String list, String item) throws SQLException 42 { 43 Connection c = null; 44 PreparedStatement statement = null; 45 ResultSet result = null; 46 47 try 48 { 49 c = getNewConnection(); 50 statement = c.prepareStatement("insert into ItemList (User, List, Item) values (?, ?, ?)"); 51 statement.setLong(1, manager.getUserID()); 52 statement.setString(2, list); 53 statement.setString(3, item); 54 55 statement.executeUpdate(); 56 } 57 finally { closeAll(c, statement, result); } 58 } 59 60 63 public void removeItem(String list, String item) throws SQLException 64 { 65 Connection c = null; 66 PreparedStatement statement = null; 67 ResultSet result = null; 68 69 try 70 { 71 c = getNewConnection(); 72 statement = c.prepareStatement("delete from ItemList where List = ? AND Item = ? AND User = ?"); 73 statement.setString(1, list); 74 statement.setString(2, item); 75 statement.setLong(3, manager.getUserID()); 76 77 statement.executeUpdate(); 78 } 79 finally { closeAll(c, statement, result); } 80 } 81 82 85 public boolean hasItem(String list, String item) throws SQLException 86 { 87 Connection c = null; 88 PreparedStatement statement = null; 89 ResultSet result = null; 90 91 try 92 { 93 c = getNewConnection(); 94 statement = c.prepareStatement("select User from ItemList where List = ? AND Item = ? AND User = ?"); 95 statement.setString(1, list); 96 statement.setString(2, item); 97 statement.setLong(3, manager.getUserID()); 98 99 result = statement.executeQuery(); 100 boolean r = false; 101 if (result.next()) 102 r = true; 103 return r; 104 } 105 finally { closeAll(c, statement, result); } 106 } 107 108 111 public String [] getList(String list) throws SQLException 112 { 113 Connection c = null; 114 PreparedStatement statement = null; 115 ResultSet result = null; 116 117 try 118 { 119 c = getNewConnection(); 120 statement = c.prepareStatement("select Item from ItemList where List = ? AND User = ?"); 121 statement.setString(1, list); 122 statement.setLong(2, manager.getUserID()); 123 124 result = statement.executeQuery(); 125 126 java.util.ArrayList a = new java.util.ArrayList (); 127 for(int i = 0; result.next(); i++) 128 a.add(result.getString(1)); 129 130 String r[] = new String [a.size()]; 131 a.toArray(r); 132 133 return r; 134 } 135 finally { closeAll(c, statement, result); } 136 } 137 } | Popular Tags |