-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.java
More file actions
56 lines (44 loc) · 1.37 KB
/
Copy pathsite.java
File metadata and controls
56 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Java Program to Illustrate JDBC Connection In Oracle DB
// Importing database
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleDriver;
// Class 1
// JDBC Connection Class
// To communicate with the database
// Note: This class is to be used in Application class
// where moto of this class is connection object
public class JDBCconnection {
// Declaring connection class object and
// initializing it to null
private static Connection connection = null;
// Method
// Static method that connects with database
public static Connection getConnection()
{
// Try block to check for exceptions
try {
// Loading and registering drivers
// using DriverManager
// Setting instance as Oracle driver
// This implies database is Oracle
DriverManager.registerDriver(
new OracleDriver());
// Passing DB- URL,username,password
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe",
"username", "password");
}
// Catch block ot handle DB exception
catch (SQLException e) {
// Display the line number where exception
// occurred using printStackTrace() method
e.printStackTrace();
}
// If no exception caught database is connected
return connection;
// Display message successful connection
System.out.print("Connection established");
}
}