You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
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;
|
|
* }
|
|
*/
|
|
}
|