|
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.sql.DriverManager;
import java.sql.SQLException;
importcom.mysql.jdbc.Connection;
publicclass JDBCTools {
public JDBCTools() {
}
publicstaticConnection getConnection() throws IOException, SQLException {
Connectionconn = null;
Properties properties = new Properties();
InputStream inStream = JDBCTools.class.getClassLoader()
.getResourceAsStream("jdbc.properties");
properties.load(inStream);
String user = properties.getProperty("user");
String password = properties.getProperty("password");
String driverClass = properties.getProperty("driverClass");
String jdbcUrl = properties.getProperty("jdbcUrl");
conn = (Connection) DriverManager.getConnection(jdbcUrl,user,password);
returnconn;
}
publicstaticvoid main(String[] args) throws IOException, SQLException {
System.out.println(getConnection());
}
} |