본문 바로가기

HttpURLConnection에서 타임아웃 설정하는 방법 HttpURLConnection에서도 타임아웃을 지정할 수 있다! 다음과 같이 해주면 된다! HttpURLConnection urlConnection = nulll int TIMEOUT_VALUE = 10000; // 타임아웃 시간. 자유롭게 지정하면 된다! 여기서는 10초로 설정해본다. try { url = new URL("..."); urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setConnectTimeout(TIMEOUT_VALUE); // 10초로 타임아웃을 설정 urlConnection.setReadTimeout(TIMEOUT_VALUE); // ReadTimeout까지 지정해주면 보다 더 안전한 어플리케이션을 만.. 더보기
ResultSet을 ArrayList<HashMap>로 변환하는 방법 ResultSet을 ArrayList로 변환하는 예제를 소개합니다. VO 등을 사용하지 않고 HashMap으로 처리할 경우 상당히 유용하게 사용할 수 있습니다! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public ArrayList convertResultSetToArrayList(ResultSet rs) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); ArrayList list = new ArrayList(); while(rs.next()) { HashMap row = new HashMap(columns); for(int i=1; i 더보기
AES256 암호화할 때 Key length not 128/192/256 bits 에러 해결 방법 자바에서 AES256 암호화를 할 때 다음과 같은 에러가 나는 경우가 있습니다. java.lang.IllegalArgumentException: Key length not 128/192/256 bits. key의 길이를 정확히 16으로 만들어주면 해결됩니다!(문자가 16개가 되도록) 다음과 같이 하면 됩니다. String key = "ABCDEF0123456789"; // 정확히 16개로 만들어야합니다. SecretKeySpec newKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); // SecretKeySpec을 생성합니다. 더보기