Wednesday, August 25, 2010
Execute an SQL script file in SQLPlus
Oracle database backup and restore
To restore database from the backup (dmp file) use following command
imp system/{system_passwd}@{schema} file={backup_file}
Where
system_passwd is password for system user
Tuesday, August 10, 2010
Creating DBLink in Oracle
create public database link {link_name}
Where
1. link_name is the name of the database link
2. user_name is the username of the database to get connected
3. connect_descriptor is the tns entry ($OARCLE_HOME/network/admin/tnsname.ora)
Friday, July 30, 2010
ORA-06550: line 1, column 91: PLS-00201: identifier 'NameFromLastDDL' must be declared
You may face below error while executing loadjava command:
ORA-06550: line 1, column 91: PLS-00201: identifier 'NameFromLastDDL' must be declared
SQL> select owner, object_name, object_type from all_objects where object_name like '%NameFromLastDDL%' ;and then install java on exist database by initjvm.sql script.
no rows selected
SQL> select comp_name, status from DBA_REGISTRY where upper(comp_name) like '%JAVA%' ;
no rows selected
http://download.oracle.com/docs/cd/B19306_01/install.102/e10319/java.htm#DFSIG276http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/scripts005.htm#sthref2935
run $ORACLE_HOME/javavm/install/initjvm.sql script.
SQL>@?/javavm/install/initjvm.sql
.
.
.
SQL> select owner, object_name, object_type from all_objects where object_name like '%NameFromLastDDL%' ;
OWNER OBJECT_NAME OBJECT_TYPE--------------- ------------------------------ -------------------SYS NameFromLastDDL FUNCTIONPUBLIC NameFromLastDDL SYNONYM
SQL> select comp_name, status from DBA_REGISTRY where upper(comp_name) like '%JAVA%' ;
COMP_NAME STATUS------------------------------------------------JServer JAVA Virtual Machine VALID
Reference: http://www.ora600.be/node/4628
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,