public void updateTag(TCTag tag) throws SQLException { try { Connection conn = DatabaseConnector.getConnection(); Statement statement = conn.createStatement(); String sql = "UPDATE tag set tag_name=" + SQLParamHelper.formatStringForSQL(tag.getTag_name()) + ", tag_content=" + SQLParamHelper.formatStringForSQL(tag.getTag_content()) + ", tag_type=" + SQLParamHelper.formatStringForSQL(tag.getTag_type()) + " where tag_id=" + SQLParamHelper.formatObjectForSQL(tag.getTag_id()); System.out.println(sql); statement.executeUpdate(sql); } catch (SQLException e) { throw e; } }
public void insertTag(TCTag tag) throws SQLException { try { Connection conn = DatabaseConnector.getConnection(); Statement statement = conn.createStatement(); String sql = "INSERT INTO tag(tag_id, tag_name, tag_content, tag_type)" + " VALUES (" + SQLParamHelper.formatObjectForSQL(tag.getTag_id()) + ", " + SQLParamHelper.formatStringForSQL(tag.getTag_name()) + ", " + SQLParamHelper.formatStringForSQL(tag.getTag_content()) + ", " + SQLParamHelper.formatStringForSQL(tag.getTag_type()) + ")"; System.out.println(sql); statement.executeUpdate(sql); } catch (SQLException e) { throw e; } }
public List<TCTag> getTags(int count) throws SQLException { try { Connection conn = DatabaseConnector.getConnection(); Statement statement = conn.createStatement(); String sql = "SELECT * from tag limit " + count; System.out.println(sql); ResultSet ret = statement.executeQuery(sql); List<TCTag> retList = new ArrayList<TCTag>(); while (ret.next()) { TCTag tag = new TCTag(); tag.setTag_id(ret.getInt("tag_id")); tag.setTag_name(ret.getString("tag_name")); tag.setTag_content(ret.getString("tag_content")); tag.setTag_type(ret.getString("tag_type")); retList.add(tag); } return retList; } catch (SQLException e) { throw e; } }
public TCTag getTag(int tag_id) throws SQLException { try { Connection conn = DatabaseConnector.getConnection(); Statement statement = conn.createStatement(); String sql = "SELECT * from tag where tag_id=" + SQLParamHelper.formatObjectForSQL(tag_id); System.out.println(sql); ResultSet ret = statement.executeQuery(sql); if (ret.next()) { TCTag tag = new TCTag(); tag.setTag_id(tag_id); tag.setTag_name(ret.getString("tag_name")); tag.setTag_content(ret.getString("tag_content")); tag.setTag_type(ret.getString("tag_type")); return tag; } else { return null; } } catch (SQLException e) { throw e; } }