-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBConnection.java
38 lines (33 loc) · 1.23 KB
/
DBConnection.java
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
package changeToYourPackageName;
import java.sql.*;
import javax.swing.JOptionPane;
public class DBConnection {
private Connection con;
public Connection getConnection(){
return con;
}
public void connectDatabase(){
try{
//load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
try{
String url,username,password;
url = "jdbc:oracle:thin:@localhost:1521:XE";
username = "yourusername";
password = "yourpassword";
koneksi = DriverManager.getConnection(url,username,password);
//Confirmation that Java has been successfully connected with oracl xe
System.out.println("Connected!");
}catch(SQLException sqle){
JOptionPane.showMessageDialog(null, "Connection Failed! " + sqle.getMessage());
System.exit(0);
}
}catch(ClassNotFoundException cnfe){
JOptionPane.showMessageDialog(null, "Driver Not Found! \n" + cnfe.getMessage());
System.exit(0);
}
}
public static void main(String[] kon) {
new DBConnection().connectDatabase();
}
}