ODBC

conn = ConnectionPool.getConnection();
connection = getClientConnection();

public static Connection getClientConnection() throws SQLException
    {
        Connection conn = null;
        try
        {
            if(!propertiesRead)
            {
                propertiesRead = true;
                Properties props = new Properties();
                props.load(new FileInputStream(new File("ClientDBConnection.properties")));
                DB_URL = props.getProperty("DB_URL");
                DB_USER = props.getProperty("DB_USER");
                DB_PASSWORD = props.getProperty("DB_PASSWORD");
            }
        
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection(DB_URL,DB_USER,DB_PASSWORD);
        }
        catch(Exception ex)
        {
            throw new SQLException("Unable to create Client Connection "+ex);
        }
        return conn;

query = new StringBuilder();
query.append(" SELECT JOINEESCOUNT FROM USERS  ");

//any conditions
if("YTD".equals(bean.getTypeOfReport())){
        query.append(" '01-Jul-"+bean.getFiscalYear()+"' AND SYSDATE ");
}

pstmt = conn.prepareStatement(query.toString());
pstmt.setInt(1,bean.getId());
rs = pstmt.executeQuery();
while(rs.next()){
      newBean.setNumOfJoinees(rs.getInt("JOINEESCOUNT"));
}

Leave a comment