Tuesday, October 30, 2012

Import & Export database oracle

Import & Export database oracle

Export database

C:\>exp old_user/password file=dbFileName

Create new user:
Go to the SQL plush and execute following query
SQL> create user new_user identified by password
Grant DBA role to this user
SQL> grant DBA to new_user;

Import database
C:\>imp new_user/password file=dbFileName fromuser=old_user touser=new_user

Wednesday, September 7, 2011

How to access "internal exception" type in JAVA

how to catch MySQLIntegrityConstraintViolationException exception


Suppose JPA entry is:

@Table(name = "players", uniqueConstraints=@UniqueConstraint(columnNames={"firstname", "lastname"}))


EJB class is:
public void create(Player player) {
try {
em.persist(player);
em.flush();
} catch (Exception e) {
e.printStackTrace();
Throwable t = getLastThrowable(e);
throw new Exception(t);
}
}



/** method to access internal exceptions */

private Throwable getLastThrowable(Exception e) {
Throwable t = null;
for(t = e.getCause(); t.getCause() != null; t = t.getCause());
return t;
}

Tuesday, November 24, 2009