본문 바로가기

카테고리 없음

DB연동

public class DBClose { 


public static void close(Statement stmt, Connection conn, ResultSet rs) { 

try { 

if (stmt != null) { 
stmt.close(); 

if (conn != null) { 
conn.close(); 

if(rs != null) { 
rs.close(); 

} catch (SQLException e) { 
e.printStackTrace(); 





}









public class DBConnection { 


public static void initConect() { 

try { 
Class.forName("oracle.jdbc.driver.OracleDriver"); 

System.out.println("Driver Loading Success"); 

} catch (ClassNotFoundException e) { 
e.printStackTrace(); 





public static Connection makeConnection() { 

Connection conn = null; 

try { 
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "hr", "hr"); 

System.out.println("DB Connection Success"); 
} catch (SQLException e) { 

e.printStackTrace(); 


return conn; 



}



Connection conn = null; // DB 정보 
PreparedStatement psmt = null; // sql query 
ResultSet rs = null; // result value