| 1 package com.Yasna.forum.database; 2 3 import com.Yasna.forum.ThreadType; 4 import com.Yasna.forum.ForumNotFoundException; 5 import com.Yasna.util.Cacheable; 6 import com.Yasna.util.CacheSizes; 7 8 import java.sql.Connection ; 9 import java.sql.PreparedStatement ; 10 import java.sql.SQLException ; 11 import java.sql.ResultSet ; 12 13 20 public class DbThreadType implements ThreadType, Cacheable { 21 private static final String SELECT="select name from yazdThreadType where typeID=?"; 22 private int ID; 23 private String name; 24 public DbThreadType(int ID){ 25 this.ID=ID; 26 Connection con = null; 27 PreparedStatement pstmt = null; 28 try { 29 con = DbConnectionManager.getConnection(); 30 pstmt = con.prepareStatement(SELECT); 31 pstmt.setInt(1,ID); 32 ResultSet rs = pstmt.executeQuery(); 33 if(rs.next()){ 34 this.name=rs.getString("name"); 35 } 36 } catch( SQLException sqle ) { 37 sqle.printStackTrace(); 38 } 39 finally { 40 try { pstmt.close(); } 41 catch (Exception e) { e.printStackTrace(); } 42 try { con.close(); } 43 catch (Exception e) { e.printStackTrace(); } 44 } 45 46 } 47 public int getID(){ 48 return ID; 49 } 50 public String getName(){ 51 return name; 52 } 53 public int getSize() { 54 int size = 0; 57 size += CacheSizes.sizeOfInt(); size += CacheSizes.sizeOfString(name); return size; 60 } 61 62 63 } 64 | Popular Tags |