Thursday, July 29, 2010
SQL Update with select
Thursday, July 15, 2010
Using java class in PL/SQL function. Example: password encryption with SHA1
1. Create java file e.g SHA1Converter.java with below code:
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
public class SHA1Converter
{
public static String SHA1(String text) throws NoSuchAlgorithmException,
UnsupportedEncodingException
{
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(text.getBytes("UTF-8"));
byte raw[] = md.digest(); //step 4
String hash = (new BASE64Encoder()).encode(raw); //step 5
return "{SHA-1}"+hash;
}
}
2. Compile java file
javac SHA1Converter.java
3. Load compile class file using openjava command. Mention schema for which you want this java class to be made available
loadjava -u
password:
arguments: '-u' 'dgmt' '-schema' 'dgmt' '-v' '-resolve' 'SHA1Converter.class'
creating : class DGMT.SHA1Converter
loading : class DGMT.SHA1Converter
resolving: class DGMT.SHA1Converter
Classes Loaded: 1
Resources Loaded: 0
Sources Loaded: 0
Published Interfaces: 0
Classes generated: 0
Classes skipped: 0
Synonyms Created: 0
Errors: 0
4. Written function to use java class and return string encrypted using SHA1
create or replace
FUNCTION gnuhash_sha1 (string IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'SHA1Converter.SHA1(java.lang.String) return java.lang.String';
5. Use above function
select gnuhash_sha1('anand') from dual;
Result : {SHA-1}uXP3dL/qtTIztPNHvhFOnKey0A8=
Wednesday, July 7, 2010
Deleting childeren in Hibernate
org.springframework.dao.InvalidDataAccessApiUsageException: deleted object would be re-saved by cascade (remove deleted object from associations): [Book#1]; ... at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657) at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881) at ConsoleScript7.run(ConsoleScript7:3)Caused by: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [Book#1]
The problem is that the books are still in the author's collection, so when the session is flushed, they will be recreated. Solution will be remove the book from the collection itself.
author.getBooks().remove(bookId)
and then save author object.Friday, June 25, 2010
Reading file from URL into byte array output stream
Thursday, March 11, 2010
Resolving java.lang.OutOfMemoryError: PermGen space in Weblogic
Hi,
Thanks,
Enable Remote Debugging in Weblogic
Hi,
In startWebLogic.cmd file, can be found at
Replace
set JAVA_OPTIONS =%SAVE_JAVA_OPTIONS%
With
set JAVA_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n %SAVE_JAVA_OPTIONS%
While starting the Weblogic you will see “Listening for transport dt_socket at address: 1044” then we are sure that debug is enabled on weblogic.
Thanks,