CRUD Operation in JSP

CRUd Opration in java/jsp….


package protech;

import protech.DataTransaction;
import java.sql.*;

public class User
{
	DataTransaction dt = new DataTransaction(true);
	private Connection conn=null;
	PreparedStatement pstmt=null;
	
	public User()
	{
		conn = dt.connection;
	}

	public int getUserIdFromDataTransaction()
	{
		return dt.getUserId();
	} 
    
	public DataTransaction dataTransactionGen()
	{
		return this.dt;
	}
	
	public ResultSet getOrgData(int notid)
	{
		ResultSet rs=null;
		String temp="";
		try
		{
			temp="select o.orgname as orname,o.orgid as orgid from organisation_master o,notification_master n,department_master d where n.notificationid="+notid+" and n.deptid=d.deptid and d.orgid=o.orgid ";
			rs=dt.viewQuery(temp);		    
			return rs;
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString());
			return null;
		}
		finally
		{
			if(rs != null)
				rs=null;
		}	    	   
	}
    
	public boolean Register(Connection c)
	{	    
		String query="insert into user_master(UserId,UserTypeId,LoginId,Password,HintQuestionId,HintAnswer) values(UserId.nextVal,?,?,?,?,?)";
		try
		{
			pstmt = conn.prepareStatement(query,PreparedStatement.RETURN_GENERATED_KEYS);
			pstmt = c.prepareStatement(query);
			pstmt.setInt(1,this.UserTypeId);
			pstmt.setString(2,this.LoginId);
			pstmt.setString(3,this.Password);
			pstmt.setInt(4,this.HintQuestionId);
			pstmt.setString(5,this.HintAnswer);
			if(pstmt.executeUpdate()<=0)
			{			 
				pstmt.close();
				return false;
			}
			else
			{			  
				ResultSet rs = dt.viewQuery("select nvl(max(UserId),0) as userid from user_master");
				if(rs.next())
				{
					this.UserId = rs.getInt("userid");
				}	
				else
				{	  
					this.UserId = 1;
				}	
				rs=null;
				pstmt.close();
				return true;
			}
		}
		catch(Exception ee)
		{
			System.out.println("Error In Register : " + ee.toString());
			return false;
		}
	}
} 

Advertisements

About Sanju
I am Software Programmer. I am working in JAVA/J2EE Technologies.

One Response to CRUD Operation in JSP

  1. Nowości kinowe says:

    you have got an ideal weblog right here! would you wish to make some invite posts on my blog?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: