07.23.08

Normalization Rules in Database

Posted in Database at 8:35 pm by vchaithanya

First normal form
First normal form states that at every row and column intersection in the table there, exists a single value, and never a list of values.

Second normal form
Second normal form requires that each non-key column be fully dependent on the entire primary key, not on just part of the key. This rule applies when you have a primary key that consists of more than one column.

Third normal form
Third normal form requires that not only every non-key column be dependent on the entire primary key, but that non-key columns be independent of each other.
Another way of saying this is that each non-key column must be dependent on the primary key and nothing but the primary key.

Fourth Normal Form
Isolate Independent Multiple Relationships

Fifth Normal Form
Isolate Semantically Related Multiple Relationships

07.21.08

Hibernate Tools setup in eclipse…

Posted in java at 11:28 pm by vchaithanya

1) In eclipse goto Help->SoftwareUpdates->Find&Install-> select Search for new features to install -> next -> select Hibernate Tools -> Finish.
2) It will show up available tools on internet -> select Hibernate Tools -> next -> accept license terms -> Finish.
3) Restart eclipse.
4) goto window -> customize perspective -> we can see Hibernate option And its list items on right side. we can open hibernate perspective in a minute.
5) Then Create a Sample Application For hibernate in Eclipse.
6) After everything works fine with the application, now its time to sync up with hibernate tools.
first goto window -> open perspective -> and open in hibernate perspective -> then
goto File -> new -> Hibernate Console Configuration -> It opens a new window, bydefault it opens up with general tab -> browse the above created Project ‘TestHb’ ->
and specify Property file and Configuration file [ use brwse] -> Finish.
7) It will open up the TestHb in Hibernate Configuration Window with three sublinks
Configuration, SessionFactory, Database. Now we sync with db
we are ready to use HQL Editor and we can see the result in Eclipse right away.

Sample Application for Hibernate in Eclipse

Posted in java at 11:03 pm by vchaithanya

1) create a new java project say ‘TestHb’
2) add the below libraries to the project. goto configure buildpath->libraries->add external jars->
antlr.jar,cglib.jar,asm.jar,asm-attrs.jar,commons-collections.jar,hibernate3.jar,jta.jar,slf4j-api.jar,slf4j-simple.jar ——-> ok
3) create “hibernate.cfg.xml” file

<hibernate-configuration> 

<session-factory>

 <property name=“hibernate.connection.driver_class”> com.microsoft.sqlserver.jdbc.SQLServerDriver </property>

 <property name=“hibernate.connection.password”>Server2005</property>

 <property name=“hibernate.connection.url”> jdbc:sqlserver://localhost:1433;DatabaseName=employee;SelectMethod=cursor </property>

 <property name=“hibernate.connection.username”>sa</property>

 <property name=“hibernate.dialect”> org.hibernate.dialect.SQLServerDialect </property>

 <property name=“current_session_context_class”>thread</property>

 <property name=“connection.pool_size”>1</property>

 <property name=“cache.provider_class”>org.hibernate.cache.NoCacheProvider</property>

 <property name=“show_sql”>true</property>

 <mapping resource=“NewMapping.hbm.xml”/>

 </session-factory

>

</
 

 

hibernate-configuration>
  4) create “NewMapping.hbm.xml” file.

 <hibernate-mapping package=“hb.db”>

<class name=“NEWENTITY” table=“NEWENTITY”>

<id name=“id” column=“ID”> </id>

<property name=“name” column=“NAME”></property>

<property name=“address” column=“ADDRESS”></property>

</class>

</hibernate-mapping>

5) create “NEWENTITY.java” bean class
package hb.db;
public class NEWENTITY {
private int id;
private String name;
private String address;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String toString()
{ return “id=”+id+”name=”+name+”address=”+address; }
}
6) create a util class for getting hibernate session factory “HibernateUtil.java”
package hb.main;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
public static final SessionFactory sFactory;
static {
try {
sFactory = new Configuration().configure().buildSessionFactory();

}catch(Throwable ex) {
System.err.println(“Initial session factory creation failed : “+ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sFactory;
}
}
7) Now its main class “EventManager.java”
package hb.main;

import hb.db.NEWENTITY;

import org.hibernate.classic.Session;

public class EventManager {

public static void main(String[] a) {
EventManager mgr = new EventManager();
mgr.createAndStoreEntity(2,”ccc”,”bellevue”);
HibernateUtil.getSessionFactory().close();
}

private void createAndStoreEntity(int id, String name, String addr) {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
NEWENTITY entity = new NEWENTITY();
entity.setId(id);
entity.setName(name);
entity.setAddress(addr);
session.save(entity);
session.getTransaction().commit();

}
8)by running the above class we can see the result, it will insert new row in ‘NEWENTITY’ in db.
9) In this application I used SqlServer2005, For other database the only file that we need to change is ‘hibernate.cfg.xml’ in that driverclass, url, dialcet.

10) you can find out all the above jars in hibernate core and hibernate annotations download in the following link

http://www.hibernate.org/6.html

 

 

07.18.08

How to implement Linked lists in JAVA

Posted in DataStructures at 6:13 pm by vchaithanya

The following is one of the cool book to get basic idea of how to implement LinkedList, Trees in java.

http://www.vias.org/javacourse/wrapnt_linked_lists151.html

07.17.08

Cannot load JDBC driver class ‘com.microsoft.sqlserver.jdbc.SQLServerDriver’

Posted in Database at 7:20 pm by vchaithanya

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class ‘com.microsoft.sqlserver.jdbc.SQLServerDriver’
;;;;;;;;;;
I got this exception when I tried to connect SQLServer2005 using Tomcat in Eclipse.
I fix this issue by placing ’sqljdbc.jar’ in tomcat/common/lib directory.

Next page