본문 바로가기

Study/JAVA29

timestamp로 SimpleDateFormat사용하기 이전 포스팅에서 현재 시간을 가지고 특정한 포맷의 date time값을 만들었었습니다. JAVA SIMPLEDATEFORMAT 별생각 없이 timestamp값을 가지고 simpledateformat으로 만들었더니 이상한 값이 출력되더군요. 자세히 살펴보니 timestamp값은 10자리 수, simpledateformat은 13자리입니다. 그 이유는 timestamp는 1970년 1월 1일 0시 0분 0초를 기준으로 초당 1씩 증가한 수이고, simpledateformat은 1970년 1월 1일 0시 0분 0초를 기준으로 밀리초당 1씩 증가한 수입니다. 그러므로 timestamp를 가지고 simpledateformat을 이용하려면 1000을 곱해주면 됩니다. 123Date date = new Date(ti.. 2016. 10. 11.
CRC16CCITT JAVA code CRC 검사중에 CRC16CCITT도 여러종류가 있습니다. Online CRC Calculation 위 링크를 따라 가 보시면 여러종류의 crc 계산을 하실 수 있습니다. 그리고 아래는 JAVA용 crc 코드입니다.(netty라서 ByteBuf를 받았는데 이부분은 수정하시면 될듯) 12345678910111213141516171819202122private static final int POLYNOMIAL = 0x1021;private static final int PRESET_VALUE = 0x0000; public static int crc16Xmodem(ByteBuf chkdata) { int length; chkdata.readerIndex(1); int crc = PRESET_VALUE; for.. 2016. 10. 11.
JAVA에서 MySQL 사용하기2 - 사용예제 1. 연결하기 123Class.forName("com.mysql.jdbc.Driver");java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://" + sqlHost, user, pw); java.sql.Statement st = con.createStatement(); Colored by Color Scriptercs Line 1 : 연결을 위해서 JDBC 드라이버 클래스를 선언해 줍니다. Line 2 : 호스트와 id, pw를 입력하여 sql서버에 접속합니다. Line 3 : statement에 연결 정보를 가져옵니다. 앞으로 statement를 이용해 query를 합니다. 2. SELECT하기 12345String sql = "SEL.. 2016. 10. 11.
JAVA에서 MySQL 사용하기1-준비 JAVA에서 MySQL을 사용하기 위해서는 JDBC가 필요합니다. JDBC 다운로드 위 링크로 들어가 J Connector를 다운 받아 압축을 풀어줍니다. 압축을 풀어 라이브러리 파일만 현재 작업중인 라이브러리 폴더로 옮깁니다. 이제 프로젝트에서 라이브러리 추가만 해주면 됩니다. 프로젝트의 properties로 들어와 Java Build Path-> Add JARs... 를 눌러 추가한 라이브러리를 선택해주면 위와 같이 라이브러리가 추가가 됩니다. 2016. 10. 11.
FrogJmp FrogJmpCount minimal number of jumps from position X to Y.Task descriptionA small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.Count the minimal number of jumps that the small frog must perform to reach its target.Write a function:class Soluti.. 2016. 7. 12.
OddOccurrencesInArray 1. OddOccurrencesInArrayFind value that occurs in odd number of elements.Task descriptionA non-empty zero-indexed array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = .. 2016. 7. 12.

인기글