For Developers

Create a Stored Procedure within a Stored Procedure

When you want to create a stored procedure dynamically,we can create a stored procedure within a stored procedure.


CREATE PROC procCreateProcedure
(
@spname NVARCHAR(100)
)
AS
BEGIN
DECLARE @ProcedureName NVARCHAR(100)
DECLARE @Exe VARCHAR(8000)


/*setting the stored procedure name with spname passed*/

SET @ProcedureName = @spname

/*setting the stored procedure name with spname passed*/

/*Nothing will be done if procedure name is empty*/
IF LTRIM(RTRIM(@ProcedureName)) = ”
BEGIN
RETURN
END
/*Nothing will be done if procedure name is empty*/


/*Creating the stored procedure*/

SET @Exe = ‘CREATE PROC ‘ + @ProcedureName + CHAR(13) +

‘AS’ + CHAR(13) + CHAR(13) +

‘BEGIN’ + CHAR(13) +

‘SELECT * FROM EMPLOYEE’+ CHAR(13) +

‘END’

/*Creating the stored procedure*/

/*Executing the created stored procedure*/
EXEC(@Exe)
/*Executing the created stored procedure*/

END

/*Executing procCreateProcedure to creat new stored procedure*/
EXEC procCreateProcedure ‘procTest’
/*Executing procCreateProcedure to creat new stored procedure*/

now execute and see the stored procedure by name you passed.

EXEC procTest


Here in this example a new stored procedure with name ‘procTest’ which is passed in ‘procCreateProcedure’ is created and employee table is fectched when ‘procTest’ stored procedure is executed.

Accessing Private Variable

Reflection in java:
Reflection is the mechanism by which Java exposes the features of a class during runtime, allowing Java programs to enumerate and access a class’ methods, fields, and constructors as objects. In other words, there are object based mirrors which reflect the Java object model, and you can use these objects to access an object’s features using runtime API constructs instead of compile time language constructs.

Each object instance has a getClass() method, inherited from java.lang.Object, which returns an object with the runtime representation of that object’s class; this object is an instance of the java.lang.Class.This object in turn has methods which return the fields, methods, constructors, superclass, and other properties of that class.

You can use these reflection objects to access fields, invoke methods, or instantiate instances, all without having compile time dependencies on those features. The Java runtime provides the corresponding classes for reflection. Most of the Java classes which support reflection are in the java.lang.reflect package.

Accessing Private Features with Reflection:
All features of a class can be obtained via Reflection, including Access to private methods & variables.Setting the Accessible flag in a reflected object of java.lang.reflect.AccessibleObject class allows us to read/modify a private variable that we normally wouldn’t have permission to. However, the access check can only be supressed if approved by installed SecurityManager.
The Classes java.lang.reflect.Field, java.lang.reflect.Method and java.lang.reflect.Constructor can inherit this behavior from java.lang.reflect.AccessibleObject class. The following example demonstrates read/modify access to a private variable which is normally inaccessible.

SimpleKeyPair.java


package com;

public class SimpleKeyPair {

private String privateKey = “Welcome SimpleKeyPair “; // private field

}

PrivateMemberAccessTest.java

package com;

import java.lang.reflect.Field;

public class PrivateMemberAccessTest {

public static void main(String[] args) throws Exception {

SimpleKeyPair keyPair = new SimpleKeyPair();

Class c = keyPair.getClass();

// get the reflected object

Field field = c.getDeclaredField(”privateKey”);

// set accessible true

field.setAccessible(true);

System.out.println(”Value of privateKey: ” + field.get(keyPair));

/* prints “Welcome SimpleKeyPair */

// modify the member varaible

field.set(keyPair, “Welcome PrivateMemberAccessTest”);

System.out.println(”Value of privateKey: ” + field.get(keyPair));

/* prints “PrivateMemberAccessTest” */

}

}


Output

=====

Value of privateKey: Welcome SimpleKeyPair

Value of privateKey: PrivateMemberAccessTest

JavaScript to Validate Email Format

Script :


var efmt=/^\w+((-\w+)(\.\w+))*\@[A-Za-z0-9]+((\.-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

function checkEmailFormat(field,msg)
{
var ctrl=document.getElementById(field);
if((!efmt.test(ctrl.value)) && ctrl.value!=”)
{
alert(msg);
ctrl.focus();
}
}

Html Code :


< type=”Text” onblur=”checkEmailFormat(’Txtemail’,'Please enter a valid email address, like sample@yahoo.com’);” id=”Txtemail” />


Demo Link

What is "CLR(Common Language Runtime)"

Common language runtime is a .NET Framework run-time environment which manages the execution of programs written in any of several supported languages. Microsoft refers to its Common Language Runtime as a “managed execution environment.

Programmers writing in any of Visual Basic, Visual C++,or C# compile their programs into an intermediate form of code called Common Intermediate Language (CIL) in a portable execution (PE) file that can then be managed and executed by the Common Language Runtime.

The CLR’s just-in-time compiler (JIT compiler) converts the CIL code into code native to the operating system.The virtual machine aspect of the CLR allows programmers to ignore many details of the specific CPU that will execute the program.

The CLR also provides other important services,such as Memory management,Thread management,Exception handling,Garbage collection,Security.


Compare two ArrayList in JSP

Compare two ArrayList:

1.ArrayList are ListOfData and SecondList

2.Include this tag in the JSP Page


<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>


3.Find the Length of the ArrayList Using fn:length tag

4.Compare the ArrayList as


<c:if test="${not empty ListOfData}" >
<c:forEach var="j" begin="0" end="${fn:length(SecondList)-1}">
<c:forEach var="i" begin="0" end="${fn:length(ListOfData)-1}">

<tr>
<c:if test="${SecondList[j].empid==ListOfData[i].empid}">
<td>${ListOfData[i].empid} </td>
<td>${ListOfData[i].empname} </td>
<td>${ListOfData[i].empdest} </td>
</c:if>
</tr>
</c:forEach>
</c:forEach>
</c:if>