DBConnection
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 db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
public static void initConnection() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Loading Success! ");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection conn = null;
// New Oracle : 우클릭 프로퍼티 -> 드라이버 프로퍼티 -> Connection Url 복사
try {
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.2.5:1521:xe", "hr", "hr");
System.out.println("DB Connection Success");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
}
|
cs |
DBCLOSE
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
|
package db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBClose {
public static void close(PreparedStatement psmt, Connection conn, ResultSet rs) {
try {
if (psmt != null) {
psmt.close();
}
if(conn != null) {
conn.close();
}
if(rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
|
cs |
'Java > jdbc' 카테고리의 다른 글
jdbc Select (0) | 2019.12.24 |
---|---|
jdbc update(DBConnection, DBClose 활용) (0) | 2019.12.23 |
jdbc delete (0) | 2019.12.23 |
jdbc Insert (0) | 2019.12.23 |
jdbc eclipse기본 설정하기 (0) | 2019.12.23 |