2011년 9월 5일 월요일

JDBC 4.0 Driver 자동 로딩 사용하기


META-INF/services/java.sql.Driver 파일을 만든다. 

파일의 내용에 driver 클래스 이름을 적어 준다. 

ex) com.ibm.db2.jcc.DB2Driver

 

java.sql and javax.sql Features Introduced in the JDBC 4.0 API

  • auto java.sql.Driver discovery -- no longer need to load a java.sql.Driver class via Class.forName
  • National Character Set support added
  • Support added for the SQL:2003 XML data type
  • SQLException enhancements -- Added support for cause chaining; New SQLExceptions added for common SQLState class value codes
  • Enhanced Blob/Clob functionality -- Support provided to create and free a Blob/Clob instance as well as additional methods added to improve accessiblity
  • Support added for accessing a SQL ROWID
  • Support added to allow a JDBC application to access an instance of a JDBC resource that has been wrapped by a vendor, usually in an application server or connection pooling environment.
  • Availability to be notfied when a PreparedStatement that is associated with a PooledConnection has been closed or the driver determines is invalid

2011년 9월 1일 목요일

pivot / unpivot query

http://it.toolbox.com/blogs/db2luw/pivot-query-12757

http://it.toolbox.com/blogs/db2luw/unpivot-query-12798

CREATE TABLE Sales (Year INT, Quarter INT, Results INT)


YEAR QUARTER RESULTS 
----------- ----------- ----------- 
2004 1 20 
2004 2 30 
2004 3 15 
2004 4 10 
2005 1 18 
2005 2 40 
2005 3 12 
2005 4 27
 
SELECT Year,
MAX(CASE WHEN Quarter = 1
THEN Results END) AS Q1,
  
MAX(CASE WHEN Quarter = 2
THEN Results END) AS Q2,
  
MAX(CASE WHEN Quarter = 3
THEN Results END) AS Q3,
  
MAX(CASE WHEN Quarter = 4
THEN Results END) AS Q4 
FROM Sales 
GROUP BY Year
 
YEAR Q1 Q2 Q3 Q4
----------- ----------- ----------- ----------- ----------- 
2004 20 30 15 10 
2005 18 40 12 27
 
 
CREATE TABLE SalesAgg
( year INTEGER,
q1 INTEGER,
q2 INTEGER,
q3 INTEGER,
q4 INTEGER );
 
YEAR Q1 Q2 Q3 Q4 
----------- ----------- ----------- ----------- ----------- 
2004 20 30 15 10 
2005 18 40 12 27
 
SELECT S.Year, Q.Quarter, Q.Results 
FROM SalesAgg AS S, 
  TABLE (VALUES(1, S.q1),
(2, S.q2),
(3, S.q3),
(4, S.q4))
AS Q(Quarter, Results);
 
YEAR QUARTER RESULTS 
----------- ----------- ----------- 
2004 1 20 
2004 2 30 
2004 3 15 
2004 4 10 
2005 1 18 
2005 2 40 
2005 3 12 
2005 4 27
 
 

WebSphere v7, 설치된 J2EE 어플리케이션 확인하기

    MBeanFactory mf =AdminServiceFactory.getMBeanFactory();
    MBeanServer server = mf.getMBeanServer();

    ObjectName obj = new ObjectName("WebSphere:type=J2EEApplication,*");
    Set<ObjectInstance> mbeans = server.queryMBeans(obj, null);

    if(mbeans!=null ) {
        Iterator<ObjectInstance> itr = mbeans.iterator();
        while(itr.hasNext()) {
            ObjectInstance objInstance =  itr.next();

            if(objInstance!=null && objInstance.getObjectName()!=null) {
                String beanName = objInstance.getObjectName().getKeyProperty("name");

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

WebSphere MBean list ( 목록 ) 확인 하기

MBeanFactory mf =AdminServiceFactory.getMBeanFactory();
List mbeanlist = mf.getMBeanTypes();
for( Object mbean : mbeanlist ){
System.out.println( mbean );
}

ConfigRepository
JVM
StatusCache
AdminOperations
J2EEDomain
ConfigService
RemoteCommandMgr
AntAgent
AppManagement
J2EEAppDeployment
DataSourceCfgHelper
NotificationService
JMXConnector
WebServer
PluginCfgGenerator
FileBrowser
Perf
PerfPrivate
SystemMetrics
TivoliPerfEngine
TivoliPerfAdvisor
ThreadPool
TargetTreeMbean
WMQConnectivityTester
ObjectPoolManager
SIBMain
PmiRmJmxService
ApplicationManager
CompositionUnitManager
Server
TraceService
RasLoggingService
SSLAdmin
DiagnosticService
ORB
HAManager
BulletinBoard
WLMAppServer
NameServer
EndpointCentralManager
TransportChannelService
SIBMQResourceDiscovery
WMQQueueDefiner
WMQInfo
WebServicesSecurityAdmin
WebServicesSecurityAlgorithmHelper
WASSchedulerCfgHelper
SecurityAdmin
FileTransferServer
TransactionService
Transaction
JMSProvider
J2CResourceAdapter
JDBCProvider
DataSource
JDBCDriver
DynaCache
WebServicesService
SdoRepository
SecurityTokenServiceAdmin
CacheableTokenMBean
ExtensionRegistryService
EJBContainer
WebcontainerDiagnosticProvider
J2EEApplication
Application
EJBModule
ObjectPool
WebContainer
PolicySetManager
SessionManager
WebModule
Servlet
Portlet
PortletApplication
AB_AlarmManager
JMSBasicFunction
JMSAdministration
ServerRuleDriverMBean
AdvisorNotificationMBean
StatelessSessionBean
JSP
CommandAssistance

2011년 8월 12일 금요일

MvsJobSubmitter 이용하여 z/WAS 에서 배치 Job JCL submit 하는 방법

 z/WAS에서 배치 Job JCL을 submit하기 위해서 다음의 사항을 먼저 체크한다.



1. z/WAS의 프로세스를 실행하는 user가 JCL이 실행되는 환경에 대한 권한이 있는지
   파일을 읽고 쓰기 위해서는 해당 데이터 셋을 읽고 쓸 수 있어야 한다.

2. submitJob , jobStatus REXX  script가 ascii 모드가 아닌지 확인 한다.
   MvsJobSubmitter는 submitJob과 jobStatus REXX script파일을 실행해서  JCL을 submit 하고 status 를 체크한다. 따라서 submitJob과 jobStatus 파일을 OMVS환경에서 봤을 때 실행가능하고 ascii 파일이 아니어야 실행할 수 있다.
   OMVS 환경에서 vi로 파일을 봤을때 정상적으로 보여야 한다. 만약 viascii로 봤을 때 내용이 보인다면 파일을 변경해야 한다. ( vi 로 새 파일을 열고 viascii에서 또는 window시스템에서 복사한 내용을 붙여 넣는 방법도 있음 )

3. jzos.script.path 환경 변수 확인
   submitJob과 jobStatus를 실행하기 위해서 해당 파일의 위치를 이 환경변수에서 찾는다.
   JZOS 압축을 풀어 놓은 곳에 sample까지 지정하면 된다. ex) /usr/lpp/jzos/sample



z/WAS에서 테스트하기 위해서는 약간의 수정이 필요 하다. MvsJobSubmitter.java를 열고 수정한다.



copyFile(), getInternalReaderWriter() 을 JSP에서 사용할 수 있도록 public 으로 변경한다.

 JSP에 job submit 하는 method를 만든다.
<%!
 MvsJob submitJob( String jclName ) throws IOException {
    MvsJobSubmitter submitter = new MvsJobSubmitter();

    submitter.copyFile( jclName, submitter.getInternalReaderWriter() );

    return submitter.submitJob();
}
%>

JSP에서 다음처럼 호출하여 job을 submit 한다.

<%
MvsJob job = submitJob("//'DATA.SET.NM(MEMBER)'");
%>


※ 이 외에 FTP를 이용하여 원격으로 job submit을 할 수도 있다. ( IBM readbook 참조 )
※ Job status를 가져오는 것은 에러가 있으나 job이 정상적으로 submit 되는 경우를 확인 함.
※ JCL file read에 문제가 있는 경우 1번항목의 권을 체크 할 것
※ JCL은 읽었으나 REXX syntax에러가 발생하는 경우 2번 항목을 체크 할 것
※ submitJob REXX script를 찾자 못하는 경우 3번 항목을 체크 할 것


2011년 8월 2일 화요일

unix shell script에서 날짜 포맷(format) 맞추기

http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/


Linux sudo 사용자 추가

/etc/group 파일의

admin 그룹에 사용자 id를 추가 하면 됨.

EJB3 Transaction

  • EJB 3 provides a built-in JTA transaction manager
  • JTA transactions and non-JTA (resource-local) transactions
  • Resource-local transactions are restricted to a single resource manager, such as a database connection


  • The default behavior described above is specified by the REQUIRED transaction attribute
  • MDBs support only the REQUIRED and NOT_SUPPORTED