rabbit mq
http://blog.saltfactory.net/90
1. table 생성
create table testuser(
id varchar2(100),
pass varchar2(100)
);
insert into testuser values('a', '1234');
insert into testuser values('b', '3456');
commit;
2. 사용되는 라이브러리들.
log4j.jar
log4jdbc3-1.2.jar
ojdbc6.jar
slf4j-api-1.5.1.jar
slf4j-log4j12-1.5.1.jar
3. SqlLogMain.java
import java.sql.*;
public class SqlLogMain {
private static final String DB_DRIVER = "net.sf.log4jdbc.DriverSpy";
private static final String DB_CONNECTION = "jdbc:log4jdbc:oracle:thin:@localhost:1521:orcl";
// private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
/
/ private static final String DB_CONNECTION = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String DB_USER = "id";
private static final String DB_PASSWORD = "pass";
public static void main(String[] args){
try {
selectRecordsFromDbUserTable();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
private static void selectRecordsFromDbUserTable() throws SQLException {
Connection dbConnection = null;
PreparedStatement preparedStatement = null;
StringBuffer strSQL = new StringBuffer();
strSQL.append("select * from testuser where id= ? ");
try {
dbConnection = getDBConnection();
preparedStatement = dbConnection.prepareStatement(strSQL.toString());
preparedStatement.setString(1, "a");
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
String pass = rs.getString("pass");
System.out.println("pass : " + pass);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (preparedStatement != null) {
preparedStatement.close();
}
if (dbConnection != null) {
dbConnection.close();
}
}
}
private static Connection getDBConnection() {
Connection dbConnection = null;
try {
Class.forName(DB_DRIVER);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER,
DB_PASSWORD);
return dbConnection;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return dbConnection;
}
}
4. properties/log4j.properties
log4j.rootLogger=INFO, console
# Console log
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %l - %m%n
log4j.logger.jdbc.sqlonly=console
5. properties 폴더를 프로젝트에 소스 폴더로 포함시킨다.
------------결과-------------
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.connectionOpened(Slf4jSpyLogDelegator.java:537) - 1. Connection opened
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. Connection.new Connection returned
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. PreparedStatement.new PreparedStatement returned
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. Connection.prepareStatement(select * from testuser where id= ? ) returned net.sf.log4jdbc.PreparedStatementSpy@1dc7e0e8
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. PreparedStatement.setString(1, "a") returned
DEBUG net.sf.log4jdbc.Slf4jSpyLogDelegator.sqlOccured(Slf4jSpyLogDelegator.java:221) - SqlLogMain.selectRecordsFromDbUserTable(SqlLogMain.java:32)
1. select * from testuser where id= 'a'
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.sqlTimingOccured(Slf4jSpyLogDelegator.java:370) - select * from testuser where id= 'a'
{executed in 13 msec}
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. ResultSet.new ResultSet returned
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. PreparedStatement.executeQuery() returned net.sf.log4jdbc.ResultSetSpy@5f122d62
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. ResultSet.next() returned true
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. ResultSet.getString(pass) returned 1234
pass : 1234
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. ResultSet.next() returned false
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. PreparedStatement.close() returned
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.connectionClosed(Slf4jSpyLogDelegator.java:556) - 1. Connection closed
INFO net.sf.log4jdbc.Slf4jSpyLogDelegator.methodReturned(Slf4jSpyLogDelegator.java:162) - 1. Connection.close() returned
Conditionally Defining Spring Beans
http://robertmaldon.blogspot.kr/2007/04/conditionally-defining-spring-beans.html
Spring Custom XML Namespace 만들기 2. 레퍼런스
jar 묶기
출처 : http://blog.daum.net/gujjy/116
입력폼을 배열로 받을때
============================================================
text, checkbox 는 name 을 그냥 같게 배열인덱스를 넣지 않는 경우
<input type='text' name='text' value='text1'/>
<input type='text' name='text' value='text2'/>
<input type='checkbox' name='ckhbx' value='aa'/>
<input type='checkbox' name='ckhbx' value='bb'/>
<input type='file' name='files/>
<input type='file' name='files/>
이런 식으로 만들고
DTO 클래스에서는 아래와 같이 만들어주면 다 쓸어 담는다.
쓸어 담는줄 알았는데... file은 배열인덱스를 넣지 않으면 안들어간다.. 썩을...
파일은 아래처럼 해야 된다...
class DTO(){
private List text;
private List ckhbx;
private List files;
//getter and setter
.....
}
org.springframework.web.multipart.commons.CommonsMultipartResolver
얘가 쓸어 담는 역할을 해주는데... 쩝.. 배열인덱스를 넣지 않은 것은 지원하지 않는다고...
===============================================
name에 배열로 명시하는 경우
text, checkbox 는 name 을 그냥 같게 배열인덱스를 넣지 않는 경우
<input type='text' name='text[0]' value='text1'/>
<input type='text' name='text[1]' value='text2'/>
<input type='checkbox' name='chkbx[0]' value='aa'/>
<input type='checkbox' name='chkbx[1]' value='bb'/>
<input type='file' name='files[0]/>
<input type='file' name='files[1]/>
이런 식으로 만들고
위와 다르게 기본 생성자를 정의하고 각 배열 객체를 초기화시켜준다.
그래야
class DTO(){
private List text;
private List chkbx;
private List files;
public Dto(){
text = new ArrayList();
chkbx = new ArrayList();
files = new ArrayList();
}
//getter and setter
.....
}
==============================================================================
두가지의 차이점은 아래의 경우 DTO 내에서 객체를 초기화 시켰기 때문에
getter로 가져와서 null 검사를 하지 않아도 된다는 것이다.
isEmpty()나 size()메서드를 바로 사용할 수 있다는 것이 좋다고 할까?
일단 모두가져와서 똑같은 작업을 하기 때문에 인덱스가 의미가 없어서..
어떤것이 좋다고 할지 모르겠다.