Wednesday, November 9, 2011

Code to Pass ArrayList From java to Oracle Database

package com.test;

import java.sql.*;
import java.sql.Connection;

public class Conn {
static String url = "jdbc:oracle:thin:@localhost:1521:oradb";

static String user = "username";

static String pass = "password";

public static Connection getConnection() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(Conn.url, Conn.user,
Conn.pass);
return conn;

} catch (Exception ms) {
ms.printStackTrace();
return null;
}
}

public static void main(String ss[]) {
Connection conn = Conn.getConnection();
}

}

public class TableTest {
int id;
String name;
String attribute1;
String attribute2;

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 getAttribute1() {
return attribute1;
}

public void setAttribute1(String attribute1) {
this.attribute1 = attribute1;
}

public String getAttribute2() {
return attribute2;
}

public void setAttribute2(String attribute2) {
this.attribute2 = attribute2;
}

}


import java.sql.Array;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import oracle.jdbc.OraclePreparedStatement;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;

public class OracleStoredProcedure {

private final String ORACLE_STRUCT = "T_TYPE";
private final String ORACLE_ARRAY = "TB_T_TYPE";

public void insertAll(List records) {
Connection conn = null;
StructDescriptor structDescriptor = null;
ArrayDescriptor arrayDescriptor = null;
int iSize = records.size();
Object[] arrObj = null;
Object[][] recObj = null;
try {

conn = Conn.getConnection();

structDescriptor = StructDescriptor.createDescriptor(ORACLE_STRUCT,
conn);
arrayDescriptor = ArrayDescriptor.createDescriptor(ORACLE_ARRAY,
conn);

arrObj = new Object[3];
recObj = new Object[iSize][3];
// Structuring obj and arrays
for (int j = 0; j < iSize; j++) {
TableTest ob = (TableTest) records.get(j);
recObj[j][0] = ob.name;
recObj[j][1] = ob.attribute1;
recObj[j][2] = ob.attribute2;

// arrObj[j] = new STRUCT(structDescriptor, conn, recObj[j]);
}
ARRAY arr = new ARRAY(arrayDescriptor, conn, recObj);
oracle.jdbc.OraclePreparedStatement preparedStatement = (OraclePreparedStatement) conn
.prepareStatement("{call POPULATE_TABLE_TEST (?)}");
preparedStatement.setArray(1, arr);
preparedStatement.execute();

} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (conn != null) {
conn.close();

}
} catch (SQLException e2) {
e2.printStackTrace();
}
}
}

public static void main(String a[]) {
List list = new ArrayList();
TableTest ab = new TableTest();
ab.setId(1);
ab.setName("user1");
ab.setAttribute1("m1");
ab.setAttribute1("m2");
list.add(ab);

TableTest abc = new TableTest();
abc.setId(2);
abc.setName("user2");
abc.setAttribute1("a1");
abc.setAttribute1("a2");
list.add(abc);
new OracleStoredProcedure().insertAll(list);

}
}

Javascript : Apply method

Javascript functions are objects with spcified property named apply. The apply method is used as the constructor of the object. The object is passed as the first parameter to the apply method. The second parameter is always an array used to initialize the object being passed with the array object.
A function named Person has three parameters and initialize the object property with the passed arguments. Here "this" refer to the object that invoke the apply method ie Aperson object. Aperson function applies Person attributes with itself as first argument and array as its parameters.


function Person(firstname,middlename,lastname)
{
this.firstname = firstname;
this.middlename= middlename;
this.lastname = lastname;
}

function Aperson(age, firstname, middlename, lastname)
{
this.age = age;
Person.apply(this, new Array(firstname, middlename, lastname))
}

aperson = new Aperson(31,"Bill","Jill","King")
console.log(aperson.firstname + " " + aperson.middlename + " " + aperson.lastname + " is " + aperson.age +" years old.") ;


Output
Bill Jill King is 31 years old.

Tuesday, November 8, 2011

Javascript: Array functions Push, Unshift, Pop, Shift

Push : The push method adds an element to the end of the array. If the method takes more than one elements, they are appended from left to right order.

var arraydata = ['a','b'] ;
arraydata.push('c');
arraydata.push('d','e');
console.log(arraydata);

Output
['a','b','c','d','e']


Unshift :The unshift method adds an element to the start of the array. If the method takes more than one elements, they are appended from right to left order.

var arraydata = ['b','a'] ;
arraydata.unshift('c');
arraydata.unshift('e','d');
console.log(arraydata);

Output
["e", "d", "c", "b", "a"]

Pop: The pop method removes an element from the end of the array and returns it.

var arraydata= ['a','b','c','d','e'];
console.log(arraydata.pop());
console.log(arraydata);

Output:
e
["a", "b", "c", "d"]

Shift : The shift method removes an element from the start of the array and returns it.

var arraydata= ['a','b','c','d','e'];
console.log(arraydata.shift());
console.log(arraydata);

Output:
a
["b", "c", "d", "e"]

arguments property of Javascript function

Javascript arguments property inside any function is array of function parameters passed. An arguments property is available only inside the function. Any function parameter can be accessed from the arguments property as usual array indexed by number starting from 0. Lets take an example.

argumentExample=function()
alert(arguments.length);
for loop counter between 0 and arguments.length
alert(arguments[counter]);

argumentExample("firstItem","secondItem",232,"fourthItem");

Callback in javascript

We create function normally to get arguments and return specific type of value in most of the programming languages. But functions in javascript behaves different. Function in javascript are objects that has predefined properties.

In javascript we can pass function as an argument and execute that passed function from the called function. We can execute passed function from the called function using the predefiend function property "call". The first parameter to the call back function acts as scope of the function and other parameters can be accessed normal way.

Lets take an example. Here function named "func" is the main function that takes an argument. Inside the function object "p" is created that has two property named "name" and "lastname". Similarly "company" object is created with property named "name" and "address". Also variable named "fullname" is created.

Another function test is created with two parameters "param1" and "param2". Here alert is given for the passed parameters and scope provided to the test from the called function.

Now we call the function "func" with the function "test" as parameter.
The line
a.call(p,fullname,company);
calls back the passed function "test". The first parameter "p" here acts as scope of the function during callback and can be accessed using keyword "this" as done on lline
alert(this.name+' ' +this.lastname);



func=function(a){
p={};
p.name='myname';
p.lastname='mylastname';
var fullname= 'abc xyz ';
company = new Object();
company.name='My Tech P. Ltd';
company.address='Nepal';
a.call(p,fullname,company);
}

test=function(param1,param2){
alert(param1);
alert(param2.name+param2.address);
alert(this.name+' ' +this.lastname);
}

func(test);

Program to send Email in Php with Authentication

PEAR Installation

PEAR is an extension for PHP. These days PEAR is included with PHP, but you need to install it yourself. I use PEAR on all my PHP developments.

Installing PEAR:

Open a command line window (i.e. Start->Run->cmd)
Go to the PHP directory, in my case C:\php. Type go-pear.bat. Follow the instructions.
The PEAR extension get installed in C:\php\PEAR directory.
Once PEAR is installed, go to the php.ini file in your Apache2 directory. Find the

Code:
;include_path = ".;c:\php\includes"

Remove the semi-colon (to un-comment it), and then add C:\php\PEAR to it

Code:
include_path = ".;c:\php\includes;C:\php\PEAR"
;include_path = ".;C:\wamp\php\includes;C:\wamp\php\PEAR"

---------------------------------------------------------------------------------------------
** The 'pear' command is not currently in your PATH, so you need to
** use 'c:\wamp\php\pear.bat' until you have added
** 'C:\wamp\php' to your PATH environment variable.

* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under C:\wamp\php\PEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.

-----------------------------------------------------------------------------------------------
#########Pear mail package Installation################

go to http://pear.php.net/package/Mail/download/ for supported Mail packages

pear install Mail-1.1.14
pear install --alldeps Mail-1.1.14

########Email with authentication#############

";
$to = "XYZ ";
$subject = "Hi!";
$body = "Hi,\n\nHow are you? This is test php mail.";

$host = "mail.domain.com";
$username = "user@myserver.com";
$password = "sdfdsf";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("

" . $mail->getMessage() . "

");
} else {
echo("

Message successfully sent!

");
}
?>

Sunday, November 6, 2011

Document Management System

Content

  1. About Document Management System.
  2. How to use Document Management System.
  3. Customer Registration.
  4. Document Transaction steps and flow diagram.
  5. Document Transaction Generation.
  6. Document Forward/Revoke/Authorize/Reject.
  7. Invalid Document.
  8. Email Notification and Alerts.
  9. User Reports.

Document Management System

A document management system (DMS) is a computer system (or set of computer programs) used to track and store electronic documents and/or images of paper documents. Document management systems are becoming more important as it becomes increasingly obvious that the paperless office is an ideal that may never be achieved. Instead, document management systems strive to create systems that can handle paper and electronic documents together.

Document management system handles documents in such a way that information can be created, shared, organized and stored efficiently and appropriately. The focus of document management system is on the organization and storage of documents. Documents are stored in an organized and secure way and allow documents to be found easily. There is a move within large organizations to use document management software to help them do this. This system is designed to make handling electronic files more efficient and effective way.

Document Management system enables the automatic routing of documents to the user responsible for working on them. Enterprises can rely on documents to be processed efficiently through a step-by-step process and there is no risk that they can be lost or overlooked. Workflow can be defined for the document processing and ensures that documents are forwarded to the appropriate user automatically at specified times, alerting the user of the necessity to process them through emails. This system ensures the smooth flow of documents through the enterprise.

In any enterprise it is vital that the security of electronic documents is appropriately managed. Document Management system ensure that access to the system is restricted only to those with the correct access permissions, both to ensure the integrity of data and to reduce the number of documents presented to the user only to those documents that are relevant to his or her role.

Document Transaction Steps and flow diagram

  1. Document Entry.
  2. Document Forward.
  3. Document Review.
  4. Document Authorize.
  5. Document Reject













Technical Details

  1. Full Open Source Implementation
  2. ZK
  3. JDK 1.6
  4. Spring Web Application Development Framework
  5. Apache Tomcat v6/ Jetty
  6. MySql
  7. Rsync
  8. Jasper Reports
  9. Linux/Fedora
  10. Enterprise Eclipse Platform for Software Development

Core Features

  1. Web Based Application
  2. Role Based Menu Access Control
  3. User Access Control
  4. User File Management
  5. Auto Email Notification
  6. Reports on Portable Document Format(PDF)
  7. Version Control
  8. Security/Access Control
  9. Support Multiple File Types
  10. Reports/Metrics
  11. Backup/Recovery