Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class DBconnect {
- private static Connection conn;
- private static String DBNAME = "test";
- private static String URL = "jdbc:oracle:thin:@localhost:1521:oracle";
- private static String USER = "KUBE";
- private static String PASSWORD = "chris1711";
- private static String DRIVER = "com.oracle.jdbc.Driver";
- public static Connection connect() throws SQLException {
- try {
- Class.forName("com.oracle.jdbc.Driver").newInstance();
- } catch (ClassNotFoundException cnfe) {
- System.err.println("Error: " + cnfe.getMessage());
- } catch (InstantiationException ie) {
- System.err.println("Error: " + ie.getMessage());
- } catch (IllegalAccessException iae) {
- System.err.println("Error: " + iae.getMessage());
- }
- conn = DriverManager.getConnection(URL, USER, PASSWORD);
- return conn;
- }
- public static Connection getConnection() throws SQLException, ClassNotFoundException {
- if (conn != null && !conn.isClosed()) return conn;
- connect();
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement