'Development/Java'에 해당되는 글 15건

출처: http://java.sun.com/products/jdbc/reference/faqs/index.html

4. How do I start debugging problems related to the JDBC API?

A good way to find out what JDBC calls are doing is to enable JDBC tracing. The JDBC trace contains a detailed listing of the activity occurring in the system that is related to JDBC operations.

If you use the DriverManager facility to establish your database connection, you use the DriverManager.setLogWriter method to enable tracing of JDBC operations.

If you use a DataSource object to get a connection, you use the DataSource.setLogWriter method to enable tracing. (For pooled connections, you use the ConnectionPoolDataSource.setLogWriter method, and for connections that can participate in distributed transactions, you use the XADataSource.setLogWriter method.)

Posted by zennken

JDBC Row Count

Development/Java 2008. 11. 28. 10:45

출처: http://java.sun.com/products/jdbc/reference/faqs/index.html

18. There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?

No, but it is easy to find the number of rows. If you are using a scrollable result set, rs, you can call the methods rs.last and then rs.getRow to find out how many rows rs has. If the result is not scrollable, you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a COUNT column in the SELECT clause.

Posted by zennken

Summary of regular-expression constructs: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html

package regExpression;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class regExTest
{
   
    public static void main(String[] args)
    {
        int count = 3;
        int i, pos, from, to;
       
        String[] texts = new String[count];
        String regEx = "%[a-zA-Z]+\\w*%";
        String matchedString;
       
        Pattern pattern = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
        Matcher matcher;
       
        texts[0] = "-=+";
        texts[1] = "%abc%--- abc --- %ba%a a123-";
        texts[2] = "a%a23456789_%";

        for (i = 0; i < count; i++)
        {
            pos = 0;
           
            matcher = pattern.matcher(texts[i]);

            System.out.println("Original String: " + texts[i]);

            while(matcher.find(pos))
            {
                matchedString = matcher.group();

                pos = matcher.end();
               
                from = matcher.start();
                to = pos -1;

                System.out.println("Matched String: " + matchedString + " (" + from  + " ~ " + to + ")");

            }
           
            System.out.println("");
        }
    }
}



실행 결과값
Original String: -=+

Original String: %abc%--- abc --- %ba%a a123-
Matched String: %abc% (0 ~ 4)
Matched String: %ba% (17 ~ 20)

Original String: a%a23456789_%
Matched String: %a23456789_% (1 ~ 12)

Posted by zennken
java -Xms<some_min_size> -Xmx<some_max_size>

-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
Posted by zennken

Java Enum Class

Development/Java 2008. 10. 6. 10:04
Since Java SE 5.0

Enum -> String: Enum에서 이름 가져오기
EnumType.Instance.name()

String -> Enum: 이름을 이용해 해당 Enum 찾기
EnumType e = (EnumType) Enum.valueOf(EnumType.class, "Name")

Instance sequence number: Instance의 순서
EnumType.Instance.ordinal()

모든 instance 가져오기
for (EnumType variable: EnumType.values())
{
...
}

switch
switch (EnumVariable)
{
case Instance: {stmt}
...
}


제목이 말하듯 Java의 enumeration은 Enum class의 child class이다.








Posted by zennken
12

zennken

달력