2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.dao;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
29 import java.sql.Connection;
30 import java.sql.DriverManager;
31 import java.sql.PreparedStatement;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34 import java.util.Properties;
36 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
39 public class FnAppDoaImpl {
42 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnAppDoaImpl.class);
44 public int getProfileCount(String driver, String URL, String username, String password) {
45 Connection dbc = null;
46 PreparedStatement pst = null;
51 dbc = getConnection(driver,URL,username,password);
52 logger.debug(EELFLoggerDelegate.debugLogger, "getConnection:::"+ dbc);
53 q = "select count(*) from fn_app";
54 pst = dbc.prepareStatement(q);
55 rs = pst.executeQuery();
59 } catch(Exception ex) {
60 logger.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
64 logger.debug(EELFLoggerDelegate.debugLogger, "count:::"+ count);
68 public static Connection getConnection(String driver2, String url, String username, String password) throws IOException, SQLException, ClassNotFoundException{
69 java.sql.Connection con=null;
71 if( url!=null && username!=null && password!=null ){
72 con = DriverManager.getConnection(url, username, password);
75 System.out.println("Connection Successful");
80 public static void cleanup(ResultSet rs, PreparedStatement st, Connection c) {
84 } catch (Exception e) {
86 logger.error("Error when trying to close result set", e);
92 } catch (Exception e) {
94 logger.error("Error when trying to close statement", e);
100 } catch (Exception e) {
102 logger.error("Error when trying to rollback connection", e);
106 } catch (Exception e) {
108 logger.error("Error when trying to close connection", e);