Tuesday, 9 September 2008
Database
------------------------------------------------------------------------------
Entity: an object in the real world that is distinguishable from other objects.
Entity Set: a collection of similar entities.
Attribute:
Key: a minimal set of attributes whose values uniquely identify an entity in the set.
Candidate key: there may be more than one attribute able to identify an entity.
Primary Key: we designate one of them as the primary key.
Relationship: an association among two or more entities.
Descriptive attributes: a relationship can have descriptive attributes.
Monday, 11 August 2008
Usage of NetBean 6.x Editor
- Ctrl + space : Code completion.
- Alt + Insert : Generate "getter and setter; constructor; delegate; add property; etc"
- Alt + Enter : ???
- Ctrl + R : factoring name.
- 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"
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有以下几种:
- org.apache.log4j.ConsoleAppender(控制台)
- org.apache.log4j.FileAppender(文件)
- org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件)
- org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生新文件)
- org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
- org.apache.log4j.HTMLLayout(以HTML表格形式布局),
- org.apache.log4j.PatternLayout(可以灵活地指定布局模式),
- org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串),
- org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)
- %p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL
- %r 输出自应用启动到输出该log信息耗费的毫秒数
- %c 输出所属的类目,通常就是所在类的全名
- %t 输出产生该日志事件的线程名
- %n 输出一个回车换行符,Windows平台为“\r\n”,Unix平台为“\n”
- %d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy MMM dd HH:mm:ss,SSS},输出类似: 2002年10月18日 22:10:28,921
- %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
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
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.
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...
-
The strictfp keyword is used to force the precision of floating point calculations (float or double) in Java conform to IEEE’s 754 standard...
-
In construction. Spring test annotations: @SpringBooTest @DataJpaTest @TestPropertySource @ActiveProfiles @Sql @SpringBootTest It is used f...
-
As the name implies, an anonymous inner class isn’t defined using an explicit name. An anonymous inner class is created when you combine ins...