public static Client searchClient(String NIC) throws ClassNotFoundException, SQLException { try { readWriteLock.readLock().lock(); Connection conn = DBConnection.getDBConnection().getConnection(); String sql = "Select * from Client where NIC='" + NIC + "'"; ResultSet rst = DBHandler.getData(conn, sql); if (rst.next()) { int marriedStatus = 1; boolean aBoolean = rst.getBoolean("MarriedStatus"); if (!aBoolean) { marriedStatus = 0; } Client client = new Client( rst.getInt("RegNo"), rst.getString("NIC"), rst.getString("ClientName"), rst.getString("Birthday"), rst.getString("Telephone"), rst.getString("Address"), rst.getDouble("AnnualIncome"), rst.getInt("GrantOwnershipPosition"), rst.getInt("PermitOwnershipPosition"), marriedStatus, rst.getInt("NumberOfMarriedSons"), rst.getInt("NumberOfUnmarriedSons")); return client; } else { return null; } } finally { readWriteLock.readLock().unlock(); } }
public static ArrayList<Client> getSimilarNames(String namePart) throws ClassNotFoundException, SQLException { try { readWriteLock.readLock().lock(); Connection conn = DBConnection.getDBConnection().getConnection(); String sql = "Select * From client where ClientName like '" + namePart + "%' order by NIC "; ResultSet rst = DBHandler.getData(conn, sql); ArrayList<Client> clientList = new ArrayList<>(); while (rst.next()) { int marriedStatus = 1; boolean aBoolean = rst.getBoolean("MarriedStatus"); if (!aBoolean) { marriedStatus = 0; } Client client = new Client( rst.getInt("regNo"), rst.getString("NIC"), rst.getString("ClientName"), rst.getString("Birthday"), rst.getString("Telephone"), rst.getString("Address"), rst.getDouble("AnnualIncome"), rst.getInt("GrantOwnershipPosition"), rst.getInt("PermitOwnershipPosition"), marriedStatus, rst.getInt("NumberOfMarriedSons"), rst.getInt("NumberOfUnmarriedSons")); clientList.add(client); } return clientList; } finally { readWriteLock.readLock().unlock(); } }
public static NominatedSuccessor searchNominateSuccessor(String NICS) throws ClassNotFoundException, SQLException { Connection conn = DBConnection.getDBConnection().getConnection(); String sql = "Select * from NominatedSuccessor where NIC_S='" + NICS + "'"; ResultSet rst = DBHandler.getData(conn, sql); if (rst.next()) { NominatedSuccessor nominateSuccessor = new NominatedSuccessor( rst.getString("NIC_S"), rst.getString("Name"), rst.getString("Address")); return nominateSuccessor; } else { return null; } }
public static int getnextOwnershiPositionGrant(String grantNumber) throws ClassNotFoundException, SQLException { try { readWriteLock.readLock().lock(); Connection conn = DBConnection.getDBConnection().getConnection(); String sql = "Select GrantOwnershipPosition From Client natural join grant1 where grantNumber ='" + grantNumber + "' order by GrantOwnershipPosition Desc limit 1"; ResultSet rst = DBHandler.getData(conn, sql); int position = 1; if (rst.next()) { position = rst.getInt("GrantOwnershipPosition") + 1; } return position; } finally { readWriteLock.readLock().unlock(); } }