Skip to main content

how to setup/configure hibernate ORM in your spring project

This article is for how to setup/configure hibernate ORM in your spring project.
Add below maven dependency in pom.xml <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.0.1.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId>

about Exceptions in Java

Exceptions in Java -
    An Exception is phenomenal condition, which can comes your program when program is executed. And this condition interrupt with program's normal flow.

    When any program face the exceptional condition, an exception object is made by JVM and program will be terminate.
            For prevent the termination of program, There is need to handle this situation.
    There are three type of exceptional event occurs.
   
1)Error
2)Checked Exceptions
3)Unchecked Exceptions


Errors -
Error can be occurs for network failure, Hardware failure or any other reason besides your programs. So you can not handle this through program code.

Checked Exceptions -
    Java compiler checks your code at compile time. If any exception occurs in this time error handler read this at compile time. This is called checked exceptions.
    IOException  are in the checked Exception.

Unchecked Exceptions -
    Unchecked exception occurs at runtime of your application. There are RuntimeException class is super class of all the Unchecked exception.

Exceptional Handling -
    In Java, Three type of exceptional handler components are try, catch and finally blocks.

Here is code with out handle the exception.

public class Test{
    public static void main(String[] args) throws CloneNotSupportedException {
        String s = "Hello how r u";
        String s1 = s.substring(0, 20);
        String ss = s+s1;
        System.out.println(ss);
    }
}

If you will run this program, exception will occurs at line no 4.

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 20
    at java.lang.String.substring(Unknown Source)
    at com.iap.mnc.common.Test.main(Test.java:4)


so use try and catch block here.


public class Test{
    public static void main(String[] args) throws CloneNotSupportedException {
        String s = "Hello how r u";
        String s1=null;
        try {
            s1 = s.substring(0, 20);
        } catch (StringIndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        String ss = s+s1;
        System.out.println(ss);
    }
}

now exception is handled by try catch block. Then next line is also execute.

Now output will be -
   
    java.lang.StringIndexOutOfBoundsException: String index out of range: 20
    at java.lang.String.substring(Unknown Source)
    at com.iap.mnc.common.Test.main(Test.java:7)
Hello how r unull

Finally block –
    Finally block will always execute when try block exist.So finally block is used for release all the object and connections which is used in try block.

Comments

Popular posts from this blog

What is NBioBSP Java Library?

The NBioBSP Java Library (NBioBSPJNI.jar) is designed to support developers using JAVA
environment.
NBioBSP Java Library based Java Native Interface Technology that facilitates easily integration of
NBioBSP by developers using Java development.
The NBioBSP Java Library also uses NBioBSP.dll and provides higher level of interfaces.
NBioBSP Java Library supports almost all NBioBSP functions.

Only valid for NBioBSP.dll version 4.781 or higher.
Only valid for JDK version 1.5.0_20 or higher.





File list :-

■ NBioBSPJNI.jar
This is the java library of the eNBSP SDK.

■ NBioBSPJNI.dll
It implements all java native interfaces. It use with the windows platform.

■ NBioBSPJNI.so
It implements all java native interfaces. It use with the Linux platform.

Draw arrow line example

Draw arrow line example - 
Its a complete example

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class Test
{
public static void main (String args[])
{
SwingUtilities.invokeLater ( new Runnable () {
Test arrows = new Test();


public void run () {
JFrame frame = new JFrame ( "Arrows" );

frame.add ( new JPanel() {
public void paintComponent ( Graphics g ) {
arrows.draw ( ( Graphics2D ) g, getWidth(), getHeight() );
}
}
, BorderLayout.CENTER );

frame.setSize ( 800, 400 );
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
frame.setVisible ( true );
}
} );
}

interface Arrow {
void draw ( Graphics2D g );
}

Arrow[] arrows = { new LineArrow(), new CurvedArrow() };

void draw ( Graphics2D g, int width, int height )
{
g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );

g.setColor ( Color.WHITE );
g.fillRect ( 0, 0, width, height );

for ( Arrow arrow : arrows ) {
g.setColor ( Color.ORANGE );
g.fillRect ( 350, 20, 20, 2…

Capture image from webcam java code, examples

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.net.MalformedURLException;
import java.net.URL;

import javax.media.Buffer;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import javax.swing.JButton;
import javax.swing.JComponent;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.ima…