±Û¾´ÀÌ :±è¿µ¼± 2000³â 6¿ù 18ÀÏ 14:08:58
In Reply to: JDBC°ü·Ã ¿À¶óŬ ¿¡·¯... posted by ±è¸Å°æ on 2000³â 6¿ù 08ÀÏ 09:58:52:
´ÙÀ½ ÄÚµå·Î Çѹø ÃʱâÈ ½ÃÄѺ¸¼¼¿ä..
----> new Database();
//¼Ò½º
import java.util.*;
import java.sql.*;
public class Database{
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
public Database(String serverName){
//String serverName = "203.237.102.167";//¼¹öÀÇ À̸§À» ÀÔ·Â ip or È£½ºÆ®À̸§
String DB_URL = ("jdbc:oracle:thin:@"+serverName+":1521:ORCL");//ÇÁ·ÎÅäÄÝÀ̸§
String ID = "scott";
String PASS = "tiger";
//driver loading
try{
Class.forName("oracle.jdbc.driver.OracleDriver");//µå¶óÀ̺êã±â
}catch(ClassNotFoundException e){
e.printStackTrace();
}
//db connect
try{
conn = DriverManager.getConnection(DB_URL,ID,PASS);//Ä¿³Ø¼ÇÇϴºκÐ
stmt = conn.createStatement();//°´Ã¼¸¦ »ý¼ºÇÏ´Â ºÎºÐ
//session connect //¼¼¼ÇÀ» ¿¬°áÇÏ´Â ºÎºÐ
}catch(SQLException e){
e.printStackTrace();
}
}
//Close the connection with the database server
//µ¥ÀÌŸº£À̽º¿ÍÀÇ ¿¬°áÀ» ÇØÁ¦throws SQLException
public void close() {
try {
conn.close();
}catch(SQLException e){
System.out.println("Disconnection error");
}
}
}