'Development'에 해당되는 글 22건
- 2009.02.26 Java Date Time
- 2009.02.25 Invoking the garbage collector
- 2009.02.19 Java Reflection
- 2009.02.10 OpenOffice의 목차에 사용자 정의 스타일을 하이퍼링크로 연결하기
- 2009.01.22 Password-Based Encryption (PBE) 기반 프로그램간의 암호화된 XML 파일교환
- 2008.12.22 Java Virtual Machine (JVM 관련자료)
- 2008.11.28 Debugging JDBC at Client side
- 2008.11.28 JDBC Row Count
- 2008.10.07 Java 정규식 예제
- 2008.10.07 JDBC Connection String for DBMSs
r.gc();
참조: http://www.devdaily.com/java/edu/pj/pj010008/pj010008.shtml
http://java.sun.com/docs/books/tutorial/reflect/TOC.html
Summary: Loading class, Instantiate an object, Invoking method
// Loading class
URLClassLoader urlClassLoader = new URLClassLoader(new URL[], file.toURL());
Class sClass = urlClassLoader.loadClass("ClassName");
// Instantiate an object
SpecificObjectType obj = sClass.newInstance();
// Invoking method
//do something: return type of "MethodName" is String in this example
Method method = sClass.getMethod("MethodName", args types ...);
result = (String) method.invoke(obj, args...);
출처: http://www.exampledepot.com/egs/javax.crypto/DesFile.html
두 프로그램간의 암호화된 XML 파일교환을 위하여 출처의 파일(DES기반)을 PBE기반으로 바꾸었다.
사용법은 보내는 쪽과 받는 쪽, 그리고 암호화 클래스(DesEncrypter)로 구성되어 있다.
이때 XML파일의 인코딩은 UTF-8을 사용한다.
보내는 쪽 (String을 파일에 암호화 시켜 저장)
String FILENAME = "test.xml";받는 쪽 (암호화 된 파일을 풀어서 스트링으로 받기)
String str2Encryption = "aaaa";
DesEncrypter encrypter = DesEncrypter.getInstance();
ByteArrayInputStream in = new ByteArrayInputStream(str4Encryption .getBytes());
encrypter.encrypt(in, new FileOutputStream(FILENAME));
in.close();
String FILENAME = "test.xml";
DesEncrypter decrypter = DesEncrypter.getInstance();
ByteArrayOutputStream out = new ByteArrayOutputStream();decrypter.decrypt(new FileInputStream(FILENAME),out);
out.close();
String result = new String(out.toByteArray());
PBE기반 암호화/복호화 클래스
// Singletone
public class DesEncrypter
{
private static DesEncrypter INSTANCE;
private final static String ENCRYPTION_SALT = "abcdefgh"; // must be 8 bytes
private final static String ENCRYPTION_PASSWORD = "password";
private final static String ENCRYPTION_ALGORITHM = "PBEWithMD5AndDES";
private final static int ENCRYPTION_ITERATION = 20;private Cipher ecipher;
private Cipher dcipher;
public static DesEncrypter getInstance()
{
if (INSTANCE == null)
{
INSTANCE = new DesEncrypter();
}
return INSTANCE;
}
private DesEncrypter() {
// Create an 8-byte initialization vector
PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParameterSpec;
SecretKeyFactory secretKeyFactory;
SecretKey secretKey;try {
pbeParameterSpec = new PBEParameterSpec(ENCRYPTION_SALT.getBytes(), ENCRYPTION_ITERATION);
pbeKeySpec = new PBEKeySpec(ENCRYPTION_PASSWORD.toCharArray());secretKeyFactory = SecretKeyFactory.getInstance(ENCRYPTION_ALGORITHM);
secretKey = secretKeyFactory.generateSecret(pbeKeySpec);
dcipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
ecipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
dcipher.init(Cipher.DECRYPT_MODE, secretKey, pbeParameterSpec);
ecipher.init(Cipher.ENCRYPT_MODE, secretKey, pbeParameterSpec);
} catch (java.security.InvalidAlgorithmParameterException e) {
} catch (javax.crypto.NoSuchPaddingException e) {
} catch (java.security.NoSuchAlgorithmException e) {
} catch (java.security.InvalidKeyException e) {
} catch (InvalidKeySpecException e) {
}
}// Buffer used to transport the bytes from one stream to another
byte[] buf = new byte[1024];public void encrypt(InputStream in, OutputStream out) {
try {
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
} catch (java.io.IOException e) {
}
}public void decrypt(InputStream in, OutputStream out) {
try {
// Bytes read from in will be decrypted
in = new CipherInputStream(in, dcipher);// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
//out.close();
} catch (java.io.IOException e) {
}
}
}
The Java Virtual Machine Specification
SDN Home > Products & Technologies > Java Technology > Java Platform,
Standard Edition (Java SE) >
http://java.sun.com/docs/books/jvms/index.html
Inside the Java Virtual Machine
http://www.artima.com/insidejvm/ed2/index.html
JVM Resource
http://www.artima.com/insidejvm/resources/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.)
출처: http://java.sun.com/products/jdbc/reference/faqs/index.html
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.
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)
ALTIBASE
jdbc:Altibase://<address>:<port_number>/<database_name>
dirver file name: Altibase.jar
ORACLE
jdbc:oracle:<drivertype>:<username/password>@<database>
<database>:
* //<host>:<port>/<service>
* <host>:<port>:<SID>
* <TNSName>
String url = "jdbc:oracle:thin:@192.168.3.38:" + port + ":orcl";
Default port: 1521
SID: select instance from v$thread;
DB Name: select name from v$database;
DB2
jdbc:db2://[serverName][:port][/DBName]
Default port 50000
The IBM® Data Server Driver for JDBC and SQLJ
--------------------------------------------------------------------------------------------
Driver package name Level of JDBC support Minimum level of SDK for Java required
--------------------------------------------------------------------------------------------
db2jcc.jar and sqlj.zip JDBC 3.0 and earlier 1.4.2
db2jcc4.jar and sqlj4.zip1 JDBC 4.0 and earlier 6
MS-SQL
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
port: 1433
sqljdbc.jar
MySQL
jdbc:mysql://<host_name>:<port_number>/<database_name>
Port: 3306