Finding all column name of table

Suppose we have a table user and we want to fetch all its column name.
For this we use INFORMATION_SCHEMA.

we will use following query to fetch all column name of table

 

Above query will fetch all columns of user table available in social database.

Read More

  1. Setting innodb_lock_wait_timeout
  2. Set time zone in mysql
  3. Granting Privileges to users
  4. Show engine innodb status
  5. Finding all column name of table

Struts1 Spring and Hibernate Integration

Register.jsp

Failure.jsp

Success.jsp

web.xml

struts-config.xml

applicationContext.xml

RegisterForm.java

RegisterAction.java

Register.hbm.xml

Register.java

RegisterDao.java

RegisterDao.Impl.java

RegisterBoImpl.java

RegisterBo.java

Struts1 and Spring Configuration Steps

  1. While integrating struts with spring provides business logic in the form of beans and the MVC layer will be provided by struts.
  2. In the order to integrate struts of spring we need plugin class called contextLoaderPlugin or contextLoaderLisenar class these are given in org.spfw.web.struts.jar.*.
  3. We need to configure the above plugin in struts-config.xml file with plugin element.
  4. In the integration the spring cfg.xml file name should <any-name.xm> and put in under of WEB-INF folder.
  5. Delegating action proxy class is responsible to communicate struts-config.xml file to spring-confg.xml file.
  6. In order to move the control form s-c.xml file.to spring cfg file we need to make use of predefined class called delighting Action Proxy class it is given in org.spfw.web.struts.* package.
  7. While integrating struts with spring the action class of struts must be cfg in the spring cfg.xml file.
  8. Action class of struts will using the object of spring bean to call the business logic so Action class is called caller bean and spring bean is all dependent object.

Spring web application

This is a complete web application of spring jdbc module of spring framework

First we write presentation logic

index.html

list.html

newaccount.html

delete.html

transaction.html

web.xml

applicationContext.xml

Templet.java

dsinter.java

insertsevlet.java

deleteservlet.java

selectservlet.java

showservlet.java

updateservlet.java

Spring MVC Basics

Spring mvc module provide the complete mvc architecture pattern implementation by only spring framework presentation layer implemented through jsp. Front controller is written in servlet and business logic is provided through special controller. In spring 2.5 provides spring mvc and spring web module are combined there is no need separate jar files. In this module has a capability to integrate other web framework, ie struts,jsf etc.

Spring DAO

This module provide the abstraction layer of spring related application

Dao Support classes are :

  1. JdbcDaoSupport – Super class for JDBC data access objects. Requires a DataSource to be set, providing a JdbcTemplate based on it to sub classes.
  2. HibernateDaoSupport – Super class for Hibernate data access objects. Requires a SessionFactory to be set,providing a HibernateTemplate based on it to sub classes. Can alternatively be initialized directly via a HibernateTemplate, to reuse the latter’s settings like SessionFactory, flush mode, exception translator, etc.
  3. JdoDaoSupport – Super class for JDO data access objects. Requires a persistenceManagerFactory to be set,providing a JdoTemplate based on it to sub classes.

Spring Transaction Management

Provides a consistent abstraction for transaction management. This abstraction is one of the most important of Spring’s abstractions wethout transaction data definition language operation is not perform, and delivers the following benefits:

1 Provides a consistent programming model across different ORM Database Layer and JDO.
2 Provides a simpler, easier to use, API for programmatic transaction transaction APIs
3 Integrates with the Spring data access abstraction
4 Supports Spring declarative transaction management

Transaction strategies

The key to the Spring transaction abstraction is the notion of a transaction strategy.
This is in org.springframework.transaction.PlatformTransactionManager interface Methods are available in transaction are

1 beginTransaction().
2 commitTransaction().
3 rolleBack().
4 setTimeout().

And these methods show TransactionException

every transaction follows ACID property

1 A atomicity.
2 C compatibility.
3 I isolation.
4 D dueribility.

We are using hibernate supported transaction management we put following code in beans in spring

The default transactions strategies are apply are as follows:

• Exception Handling: RuntimeExceptions roll-back, normal (checked) Exceptions don’t
• Transactions are read/write
• Isolation Level: TransactionDefinition.ISOLATION_DEFAULT
• Timeout: TransactionDefinition.TIMEOUT_DEFAULT

Spring Aspect Oriented Programming

AOP is a Aspect Oriented Programming not a object oriented programming this is a methodology to provide other middle ware services such as security transaction management etc.
Spring AOP is implemented in pure Java. There is no need for a special compilation process. Spring AOP does not need to control the class loader hierarchy, and is thus suitable for use in a J2EE web container or application server.

Spring AOP provides other methodology such as join,join points,point cuts,advice.
Different advice types include are

1 Around advice
2 Before advice
3 Throws advice
4 After returning advice

Spring Bean Example

This application is the example of been collaboration that means one bean injecting the information of other beans
Book.java

This is normal pojo class

BookInter.java

this is implementation details class file

CommandLineView.java

this class displaying the out put.

book.xml

This is client application of all application

Output

Spring configuration first example

Resource of spring core module Applications are used
1 Spring interface.
2 Spring bean class.
3 Spring- configuration file.
4 Client Applications
All the spring releted jar files put in lib folder directory structure is same as normal java/j2ee applications.

Demo.xml

This example is setter base dependency injection this xml file is spring configuration file we set all those bens in this xml file. Again we create interface and its implantation class.

DemoInterImpl.java

DemoInter.java

DemoClient.java

When we compile and run this program this will print massage with username and current date and time.