-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOracleTest.java
More file actions
48 lines (48 loc) · 1.81 KB
/
OracleTest.java
File metadata and controls
48 lines (48 loc) · 1.81 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
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
/* ++++++++++++++++++++++++++++++++++++++++++++++
Make sure you did the following before execution
1) Connect to WPI's wifi or vpn
2) Create an Oracle data source and successfully create a connection
3) Write your java code (say file name is OracleTest.java) and then compile it
using the following command
> javac OracleTest.java
4) Run it
> java OracleTest
++++++++++++++++++++++++++++++++++++++++++++++ */
public class OracleTest {
public static void main(String[] argv) throws SQLException {
System.out.println("-------- Oracle JDBC Connection Testing ------");
System.out.println("-------- Step 1: Registering Oracle Driver ------");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver? Did you follow the execution steps. ");
System.out.println("");
System.out.println("*****Open the file and read the comments in the beginning of the file****");
System.out.println("");
e.printStackTrace();
return;
}
System.out.println("Oracle JDBC Driver Registered Successfully !");
System.out.println("-------- Step 2: Building a Connection ------");
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@oracle.wpi.edu:1521:orcl",
"your oracle username",
"your oracle password");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it. Connection is successful. Take control of your database now!");
} else {
System.out.println("Failed to make connection!");
}
connection.close();
}
}