Monday, 11 August 2008

Usage of NetBean 6.x Editor

Hot keys:
  1. Ctrl + space : Code completion.
  2. Alt + Insert : Generate "getter and setter; constructor; delegate; add property; etc"
  3. Alt + Enter : ???
  4. Ctrl + R : factoring name.
  5. Shift + Esc : enlarge current window.

Tutorial on using NetBean IDE

Persist LOB using JPA in J2EE/J2SE

-----------------------------------------------------------------------------------------------
JPA (Sun persistence standard)==> Persistence Provider (Toplink) ==> JDBC (version 11.)

1) JPA provides a simple solution for persisting LOB in Database. Developer only need to annotate the Entity variable that is a LOB. Looks like that, at least from the document, that I have read.
2) However, persistence manager seems cannot persist a string bigger than 4000 byte. Why?
//------------------------------------------------------------------------------------------------
The reason is that the JDBC driver, I am using, ojdbc14.jar, which is only compatible for jdk1.4 not for jdk1.5. It doesn't support write BLOB into database just like writing in a String. So I download the latest version JDBC driver, ojdbc5.jar, and problem solved at once.
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
JDBC driver: ojdbc14.
  • Specification-Title: "Oracle JDBC driver classes for use with JDK1.4"
  • Specification-Version: "Oracle JDBC Driver version - 9.0.2.0.0"
JDBC driver 10.2 above, it can treat Clob as if they were strings, with code like:

ps = conn.createPreparedStatement( "update tab set lob =?");
ps.setString(1,"Bob")

The actual way this is done internally depends on the size of String set on the bind-parameter.

Better performance can be squeezed out of this for String between 4000 bytes and 32Kb, using a bit of PL/SQL:

ps = conn.prepareStatement("begin \n
update tab set lob= ? where id = ?;\n
End;")
Ps.setString(1, StringUpTo32K);



Log4j notes


log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n

Log4j提供的appender有以下几种:
  1. org.apache.log4j.ConsoleAppender(控制台)
  2. org.apache.log4j.FileAppender(文件)
  3. org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件)
  4. org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生新文件)
  5. org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
Log4j提供的layout有以下几种:
  1. org.apache.log4j.HTMLLayout(以HTML表格形式布局),
  2. org.apache.log4j.PatternLayout(可以灵活地指定布局模式),
  3. org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串),
  4. org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)
Log4j 自定义格式
  1. %p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL
  2. %r 输出自应用启动到输出该log信息耗费的毫秒数
  3. %c 输出所属的类目,通常就是所在类的全名
  4. %t 输出产生该日志事件的线程名
  5. %n 输出一个回车换行符,Windows平台为“\r\n”,Unix平台为“\n”
  6. %d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy MMM dd HH:mm:ss,SSS},输出类似: 2002年10月18日 22:10:28,921
  7. %l 输出日志事件的发生位置,包括类目名、发生的线程,以及在代码中的行数。举例:Testlog4.main(TestLog4.java:10)

Tuesday, 8 April 2008

Error-See Servlet Spec 2.3, section 9.7.2. Offending class:

When I upload udlandscall.war into test server (Tomcat), which gave following errors:


"2008-04-08 14:52:01 org.apache.catalina.loader.WebappClassLoader validateJarFile

INFO: validateJarFile(/home/plastest/tomcat/webapps/udlandscall/WEB-INF/lib/servlet.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

2008-04-08 14:52:01 org.apache.catalina.startup.HostConfig deployWAR

SEVERE: Error deploying web application archive udlandscall.war"

Reason:
"The classloader that a container uses to load a servlet in a WAR must allow the
developer to load any resources contained in library JARs within the WAR
following normal J2SE semantics using getResource. It must not allow theWAR to
override J2SE or Java servlet API classes. It is further recommended that the loader
not allow servlets in theWAR access to the web container’s implementation classes.
It is recommended also that the application class loader be implemented so
that classes and resources packaged within the WAR are loaded in preference to
classes and resources residing in container-wide library JARs."

The problem is that you are having some of the jar files which are not supposed to be in your war but in container(tomcat) e.g. servlet.jar. It is very common mistake to keep these jars in WEB-INF/lib folder for compilation and ship it with the war file.



Friday, 9 November 2007

JDBC access any kind of tabular data in a relational database

Basic procedures.

1) Connecting to a data source, like database.
Connection con = DriverManager.getConnection( "jdbc:myDriver:wombat", "myLogin","myPassword");

2)Sending query or update statements to the database.
Statement stmt = con.createStatement();

3) Retrieve and process the results received from database in answer to the query.
while (rs.next()) {
int x = rs.getInt("a");
String s = rs.getString("b");
float f = rs.getFloat("c"); }

Wednesday, 19 September 2007

Some Iterms often as reading J2EE

1. Java Naming and Directory Interface (JNDI), it is used to build powerful and portable directory-enabled applications.

2. Java Message Service (JMS), it's a reliable Enterprrise Messaging standard. Enterprise messaging is also referred to as Messaging Oriented Middleware (MOM), is universally considered as an essential tool for building enterprise applications when needing the asynchronous exchange of critical business data. The JMS api provide framework to develop portable, message based application in the Java programming language.

Friday, 14 September 2007

Communication between distributed program via internet

IIOP is a critical part of a strategic indusctry standard, the Common Object Request Broker Architecture (CORBA). Using CORBA's IIOP and related protocols, a company can write programs that will be able to communicate with their own or other company's existing or future programs whereever they are located and without having to understand anything about the program other than its service and name.

SOAP was developed by Microsoft, DevelopMentor, and Userland Software, and has been proposed as a standard interface to the Internet Engieering Task Force (IETF). SOAP(Simple Object Access Protocol) is a way for a program running in one kind of operating system to communicate with a program in the same or another kind of an operating system such as Linux by using HTTP and its XML as the mechanisms for information exchange.

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...