package com.example.utility; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; public class Connect { private Properties properties = new Properties(); private Connection connection; public Connection databaseConnect() throws IOException { InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties"); properties.load(inputStream); String jdbcUri = properties.getProperty("jdbcUri"); String jdbcUser = properties.getProperty("jdbcUser"); String jdbcPassword = properties.getProperty("jdbcPassword"); String jdbcDriver = properties.getProperty("jdbcDriver"); try { Class.forName(jdbcDriver); } catch (ClassNotFoundException e) { System.out.println(e.getMessage()); } try { connection = DriverManager.getConnection(jdbcUri, jdbcUser, jdbcPassword); } catch (SQLException e) { System.out.println(e.getMessage()); } return connection; } /* * public int databaseClose() { * try { * connection.close(); * } catch (SQLException e) { * return -1; * } * return 0; * } */ }