HttpClient client = new HttpClient();
  client.getParams().setParameter("http.connection.timeout", 5*1000); //접속 지연 시간 설정
  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, false)); //재시도 횟수 설정

 

'Programming > JAVA' 카테고리의 다른 글

Using openCSV in JAVA  (0) 2013.11.20
이클립스 JSP plug in / 환경설정  (3) 2011.03.24
JDBC 문법  (2) 2011.03.24
JDBC 설정  (2) 2011.03.24
JAVA IO  (1) 2011.03.24

openCSV 라이브러리를 이용한 자바 개발 Tutorial

※ 파일을 읽고 or 쓰고 난 후 Reader(), Writer()는 꼭 .close() 하자!!

 

http://chuudok.cafe24.com/blog/900

 

 

'Programming > JAVA' 카테고리의 다른 글

HttpClient connection 설정 관련(timeout, RetryHandler)  (0) 2013.11.27
이클립스 JSP plug in / 환경설정  (3) 2011.03.24
JDBC 문법  (2) 2011.03.24
JDBC 설정  (2) 2011.03.24
JAVA IO  (1) 2011.03.24

1. 플러그인 다운로드

 - http://www.eclipsetotale.com/tomcatPlugin.html


2. 압축을 풀어 이클립스의 plugins의 폴더에 넣는다.


3. 가장먼저 workspace를 웹폴더로 설정한다

  - JSP 환경에 맞게 환경설정을 새로 해야 하기 때문이다.


4. 이클립스를 실행하여 상단에 고양에 3마리 아이콘을 확인 한 후 환경설정에서 tomcat 메뉴를 확인

 1) tomcat

 - 현재 버전을 체크하고 설치된 폴더를 지정 해 준다.

 - context declaration mode 는 server.xml로 선택 한 후 conf폴더 밑에 server.xml을 선택한다.

 2) Advanced

  - 여기서도 톰캣의 홈을 설정

 3) Tomcat Manager App

  - 매니저의 ID와 PWD를 입력 후 저장!

'Programming > JAVA' 카테고리의 다른 글

HttpClient connection 설정 관련(timeout, RetryHandler)  (0) 2013.11.27
Using openCSV in JAVA  (0) 2013.11.20
JDBC 문법  (2) 2011.03.24
JDBC 설정  (2) 2011.03.24
JAVA IO  (1) 2011.03.24

1. JDBC 사용 기본 문법


 1) 가장 기본적인 문법.

 import java.sql.*;  //1. 임포트하자. 

public class JDBCTest {

public static void main(String[] args) {

//2. JDBC 드라이버 설치 (JAVA 설치되 경로의 ext 폴더에 넣어준다)

String driver = "oracle.jdbc.driver.OracleDriver";

String url = "jdbc:oracle:thin:@localhost:1521:XE";  //jdbc의 버전과 드라이버정보를 표기한 후 접속할 IP와 Port번호와 SID를 입력.

try{

Class.forName(driver);

}catch(ClassNotFoundException ex){

System.out.println("Class Not Found");

}

//3. Oracle DB에 Connection 하자.

//4. Statement  객체 생성하자.

//5. SQL 실행

// String sql = "SELECT SYSDATE FROM dual";

String sql = "Select zipcode, sido, gugun,dong,bunji From zipcode Where dong like '%야탑동%' Order by zipcode";

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

try{

conn = DriverManager.getConnection(url,"scott","tiger");

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

rs.next(); // rs값의 첫번째 값을 읽는다!

java.util.Date now = rs.getDate(1);

System.out.println(now);

}catch(SQLException ex){

System.out.println(ex);

}

//6. Close 하자

finally{

try{

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

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

}catch(SQLException ex){

System.out.println(ex);

}

}

}

}


 2) DriverManager를 이용해 Driver를 등록하는 방법

 import java.sql.DriverManager;

import java.sql.SQLException;

public class JDBCTest {

public static void main(String[] args) {

//DriverManager를 이용한 Driver Loading

try{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); 

//deregisterDriver로 해제 가능

System.out.println("성공");

}catch(SQLException ex){}

}

}



 3) properties를 이용한 DB 정보 입력

 public DBBean(){//Constructor

info = new Properties();

try{

info.load(new FileInputStream("D:\\OracleRoom\\dbinfo.properties"));

}catch(IOException ex){

System.out.println(ex.toString());

}

}







2. Java 에서 DB의 접근 속도를 줄이는법.

 1) Prepared Statement

   - 처음 문장을 선언할 때 문법 검사를 하지않고 마지막 값을 넣을 때 문법 검사를 하기때문에 속도가 더 빠르다.

 Connection conn = bean.getConnection();

int[] deptnoArray = {50,60,70,80,90};

String[] dnameArray = {"전산실","영업부","관리부","자재부","총무부"};

String[] locArray = {"서울","부산","대전","광주","대구"};

String sql = "Insert into dept(deptno, dname, loc) Values (?,?,?)"; //값을 넣지 않고 지나간다.

PreparedStatement pstmt = conn.prepareStatement(sql);

for (int i = 0; i < 5; i++) {

pstmt.setInt(1, deptnoArray[i]);

pstmt.setString(2, dnameArray[i]);

pstmt.setString(3, locArray[i]);

int row = pstmt.executeUpdate();

System.out.println(row +"개의 행이 반영됨");

}

bean.connClose();


 2) Batch 파일 형태로 쿼리를 한번에 모와서 실행하는 방법

 Connection conn = bean.getConnection();

int[] deptnoArray = {50,60,70,80,90};

String[] dnameArray = {"전산실","영업부","관리부","자재부","총무부"};

String[] locArray = {"서울","부산","대전","광주","대구"};

Statement stmt = conn.createStatement();

for (int i = 0; i < 5; i++) {

String sql = "Insert into dept values("+deptnoArray[i]+",'"+dnameArray[i]+"','" +locArray[i]+"')";

stmt.addBatch(sql);   // 쿼리문 저장,

}

int [] row = stmt.executeBatch();  //한번에 실행

System.out.println(row.length+"개의 행이 반영되었습니다");

bean.connClose();


'Programming > JAVA' 카테고리의 다른 글

Using openCSV in JAVA  (0) 2013.11.20
이클립스 JSP plug in / 환경설정  (3) 2011.03.24
JDBC 설정  (2) 2011.03.24
JAVA IO  (1) 2011.03.24
JAVA Threads  (2) 2011.03.24

+ Recent posts