ResultSet rowcount 구하기

java 2014. 3. 14. 10:23

ResultSet은 불편하게도 총 건수를 구하는 method를 제공하지 않는다.. ㅡ_ㅡ


그러다 보니 다음과 같은 꼼수..  라고 하기는 좀 그러지만..  아래와 같이 구한다..


        String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";    

        String user = "muse";

        String passwd = "muse";

        Connection conn;

        Statement stat; 

        ResultSet rs = null;

        int rowcount = 0;

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

        conn = DriverManager.getConnection (url, user, passwd);


        stat = conn.prepareStatement("select * from tab1 where col1 = ?",

          ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)

        stat.setString(1,"ddd");

 

  //이러한  방법으로 rowcount를 구한다..

rs.last();

rowcount = rs.getRow();

rs.beforeFirst();



stat 생성시..  

ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE  추가하지 않고

conn.prepareStatement("select * from tab1 where col1 = ?");

선언하면..

rs.last(); 부분에서 

Invalid operation for forward only resultset : last 에러가 발생한다.


Posted by 무세1
,

오늘 날짜를 문자 YYYYMMDD  포맷으로 나오게 하는 방법

import java.util.Calendar;

import java.text.SimpleDateFormat;


public class testToday{

    public static void main(String args[]){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        Calendar c1 = Calendar.getInstance();

 String strToday = sdf.format(c1.getTime());


        System.out.println("Today=" + strToday);

    }

}


'java' 카테고리의 다른 글

java 현재시간과 시간 지연  (0) 2014.03.18
ResultSet rowcount 구하기  (0) 2014.03.14
ORA-01861: literal does not match format string 오류발생..  (0) 2014.02.28
java String -> hex 변환  (0) 2014.02.20
java String <-> int 변환  (0) 2014.02.19
Posted by 무세1
,

프로그램 작성시...

쿼리툴에서는 잘 돌아가는데..  java 프로그래밍에서는 오류가 발생한다..

ORA-01861: literal does not match format string

select  TO_CHAR(TO_DATE(?),'YYYYMMDD') from dual;  //오류발생

그래서 이걸 다음과 같이 수정

select  TO_CHAR(TO_DATE(?,'YYYYMMDD'),'YYYYMMDD') from dual;  //정상


날짜관련 함수를 사용하는 SQL에서는..  가끔 이런 오류가 발생한다..

이럴땐 날짜관련 함수를 의심하면 된다..

'java' 카테고리의 다른 글

ResultSet rowcount 구하기  (0) 2014.03.14
java 오늘일자 string format YYYYMMDD  (2) 2014.03.12
java String -> hex 변환  (0) 2014.02.20
java String <-> int 변환  (0) 2014.02.19
aes256 암호화 java 샘플  (0) 2014.01.27
Posted by 무세1
,

java String -> hex 변환

java 2014. 2. 20. 10:53

apache common lib를 이용해서 수행

commons-codec-1.5.jar


String hexStr = "fd00000aa8660b5b010006acdc0100000101000100010000";    
byte[] bytes = Hex.decodeHex(hexStr.toCharArray());
System.out.println(new String(bytes, "UTF8"));


commons-codec-1.5.jar


Posted by 무세1
,

java String <-> int 변환

java 2014. 2. 19. 15:04
  1. String -> int 변환
    • Integer.parseInt(String);
  2. int -> String 변환
    • Integer.toString(int);

       


Posted by 무세1
,

aes256 암호화 java 샘플

java 2014. 1. 27. 23:42


ase256 java 예제입니다.


 여기로....

'java' 카테고리의 다른 글

ORA-01861: literal does not match format string 오류발생..  (0) 2014.02.28
java String -> hex 변환  (0) 2014.02.20
java String <-> int 변환  (0) 2014.02.19
java.security.InvalidKeyException: Illegal key size 오류  (0) 2014.01.25
jsp precompile  (0) 2014.01.23
Posted by 무세1
,

ASE-256 암호화시..

java.security.InvalidKeyException: Illegal key siz  오류 발생하면..


http://www.oracle.com/technetwork/java/javase/downloads/index.html 에서

Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 7 

다운로드한후
압축을 풀면...  local_policy.jar ,  US_export_policy.jar 파일이 나온다..

C:\Program Files\Java\jre7\lib\security 폴더에  덮어쓰우면 된다...

주의할점은..
C:\Program Files\Java\jdk1.7.0_45\jre\lib\security 폴더에 덮어쓰우면..  오류난다..
하루내내 삽질한 기억이..  OTL..




'java' 카테고리의 다른 글

ORA-01861: literal does not match format string 오류발생..  (0) 2014.02.28
java String -> hex 변환  (0) 2014.02.20
java String <-> int 변환  (0) 2014.02.19
aes256 암호화 java 샘플  (0) 2014.01.27
jsp precompile  (0) 2014.01.23
Posted by 무세1
,

jsp precompile

java 2014. 1. 23. 11:14

java weblogic.jspc -compileAll -d /tmp -encoding UTF-8 -k -webapp /WebAppDir

 

-d: 컴파일된 jsp의 클래스가 위치할 디렉토리 위 예를 따르면, /tmp/jsp_servlet 라는 곳에 class파일 생성

-k: 컴파일 시 오류가 발생하더라도 계속 컴파일 실행.

-webapp: Name of a directory containing a Web Application in exploded directory format

Posted by 무세1
,