Java SE 6 新特性: Java DB 和 JDBC 4.0

2006 年底,Sun 公司发布了 Java Standard Edition 6(Java SE 6)的最终正式版,代号 Mustang(野马)。跟 Tiger(Java SE 5)相比,Mustang 在性能方面有了不错的提升。与 Tiger 在 API 库方面的大幅度加强相比,虽然 Mustang 在 API 库方面的新特性显得不太多,但是也提供了许多实用和方便的功能:在脚本,WebService,XML,编译器 API,数据库,JMX,网络和 Instrumentation 方面都有不错的新特性和功能加强。 本系列 文章主要介绍 Java SE 6 在 API 库方面的部分新特性,通过一些例子和讲解,帮助开发者在编程实践当中更好的运用 Java SE 6,提高开发效率。 本文是系列文章的第 5 篇,介绍了 Java SE 6 在数据库编程方面的新特性。 长久以来,由于大量(甚至几乎所有)的 Java 应用都依赖于数据库,如何使用 Java 语言高效、可靠、简洁地访问数据库一直是程序员们津津乐道的话题。新发布的 Java SE 6 也在这方面更上层楼,为编程人员提供了许多好用的新特性。其中最显著的,莫过于 Java SE 6 […]

Extract from Abstract Syntax Notation One (ASN.1)

E.1 What is ASN.1?ASN.1 is the acronym for Abstract Syntax Notation One, a language for describing structured information; typically, information intended to be conveyed across some interface or communication medium. ASN.1 has been standardised internationally. It is widely used in the specification of communication protocols. Prior to ASN.1, information to be conveyed in communication protocols […]

Developing Struts Web Module

In this section we will build and test our Struts Hibernate Integration application. Compiling and packaging application Since we are using ant build tool, so the compiling and packaging will done by ant tool. To compile and create war file for deployment, open console and go to “C:\Struts-Hibernate-Integration\code\WEB-INF\src” directory. Then just type ant, ant will […]

Developing Struts Web Module

In this we will be creating search interface for enabling the user to search tutorials. This example is an client to test our Struts Hibernate Plugin. The web component of the application consists of the following files: 1. Search Tutorial Form (SearchTutorial.jsp): This file is used to display the search form to the user. Here […]

Developing Struts Hibernate Plugin

In this section we will develop java code for Struts Hibernate Plugin. Our Hibernate Plugin will create Hibernate Session factory and cache it in the servlet context. This strategy enhances the performance of the application. Source Code Of Hibernate Struts Plugin: package roseindia.net.plugin;import java.net.URL;import javax.servlet.ServletContext;import javax.servlet.ServletException;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.struts.action.ActionServlet;import org.apache.struts.action.PlugIn;import org.apache.struts.config.ModuleConfig;import org.hibernate.HibernateException;public class HibernatePlugIn implements PlugIn {   private String _configFilePath = “/hibernate.cfg.xml”;    /**     * the key under which the <code>SessionFactory</code> instance is stored     * in the <code>ServletContext</code>.     */    public static final String SESSION_FACTORY_KEY             = SessionFactory.class.getName();  private SessionFactory _factory = null;   public void destroy() {     try{       _factory.close();     }catch(HibernateException e){      System.out.println(“Unable to close Hibernate Session Factory: ” + e.getMessage());     }          }   public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {     System.out.println(“*************************************”);   System.out.println(“**** Initilizing HibernatePlugIn   **********”);        Configuration configuration = null;        URL configFileURL = null;        ServletContext context = null;   try{            configFileURL = HibernatePlugIn.class.getResource(_configFilePath);            context = servlet.getServletContext();            configuration = (new Configuration()).configure(configFileURL);            _factory = configuration.buildSessionFactory();      //Set the factory into session      context.setAttribute(SESSION_FACTORY_KEY, _factory);   }catch(HibernateException e){    System.out.println(“Error while initializing hibernate: ” + e.getMessage());   }   System.out.println(“*************************************”);   }    /**     * Setter for property configFilePath.     * @param configFilePath New value of property configFilePath.     */    public void setConfigFilePath(String configFilePath) {        if ((configFilePath == null) || (configFilePath.trim().length() == 0)) {            throw new IllegalArgumentException(                    “configFilePath cannot be blank or null.”);        }                System.out.println(“Setting ‘configFilePath’ to ‘”  + configFilePath + “‘…”);        _configFilePath = configFilePath;    }/*(SessionFactory) servletContext.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);*/  } In our plugin class we have define a variable _configFilePath to hold the […]

Writing Hibernate Configuration Files

In the previous section we completed the database setup and created required table and populated with the data. In this section we will write required hibernate configuration files. For this tutorial we need following Hibernate configuration files: Hibernate Configuration File Hibernate configuration file (hibernate.cfg.xml) is used to provide the information which is necessary for making […]

Downloading Struts & Hibernate

In this we will download Struts & Hibernate and setup the development environment. Downloading Hibernate Hibernate is free open source software it can be download from http://www.hibernate.org/. Visit http://www.hibernate.org/ and then click on the Download link to go to the download page. From the download page download the current latest release of Hibernate Core. For […]

Setting up MySQL Database and Tables

I am assuming that you have running instance of MySQL Database and you know how to work with the MySQL database. To access the database you should have valid user name and password.  Let’s now start by creating the database for our struts- hibernate integration tutorial. Our application is very very simple and it searches […]

Struts Hibernate Integration

In this tutorial I will show you how to integrate Struts and Hibernate. After completing this tutorial you will be able to use Hibernate in your Struts project. We will be using Hibernate Struts plug-in to write high performance application using Struts and Hibernate. Hibernate is Object-Oriented mapping tool that maps the object view of […]

Struts 2 Tutorials

Struts 2 Tutorials Introduction to Struts 2Introduction to Struts 2 framework. Struts Hibernate Integration Tutorial NEWIn this tutorial I will show you how to integrate Struts and Hibernate. After completing this tutorial you will be able to use Hibernate in your Struts project. Download the source code of Struts Hibernate Integration Tutorial. Struts Hibernate Integration […]