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