Tuesday, 4 August 2015

Establish a connection with Sqlserver using Jdbc


Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  // load the driver

Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=Movie;user=sa;pass word=City05;");   

Note :

Before establishing a connection from server using jdbc first download a specific driver , in this context we downloaded "Sqljdbc4.jar". after download add this file in your project under Lib directory,

Delete duplicate entry from sqlserver table

Remove Repeted entry  from a table .


let us learn how to delete duplicate data from table .
Suppose there is a table with name “Employee” with two columns Id and Name , and there is no primary key involved in this table , hence there is possibility of having repeated values now , we have to delete those repeated values.

With empTemp as
(
Select *,row_number() over(partition by id, name order by id, name) as empTemp from employee
)
Delete from empTemp where empTemp>1


Note :

Row_number() : Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.

Over :  the OVER clause defines a window or user-specified set of rows within a query result set. A window function then computes a value for each row in the window. You can use the OVER clause with functions to compute aggregated values such as moving averages, cumulative aggregates, running totals, or a top N per group results.
With  : Specifies a temporary named result set, known as a common table expression (CTE).

Saturday, 14 September 2013

Custom Tag [with body]



1.   Create a handler file  like :  myTag.java

 package mypac;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
// writer:  @author ashy
public class myTag extends BodyTagSupport {
      /** Creates a new instance of myTag */
    public myTag() { }
     String color;
        public void setColor(String color)
        {
        this.color=color;
        }
    public int doStartTag()throws JspException
    {    try
        {
        JspWriter jw=pageContext.getOut();
     jw.println("<table bgcolor='"+color+"'");
     jw.println("><tr><td>");
      
        }
     catch(Exception e)
     {         }
return EVAL_BODY_INCLUDE;
    }
    public int doEndTag()
    {
        try{
              JspWriter jw=pageContext.getOut();
      jw.println("</td><tr/></table>");
        }
catch(Exception e)
        {    }
        return EVAL_PAGE;
    }      
}
2.  Create a tag handler under tlds folder under WEB-INF folder like:bodyTagLib.tld
Code:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>bodytaglib</short-name>
  <uri>/WEB-INF/tlds/bodyTagLib</uri>
    <tag>
              <name>ashwani</name>
       <tag-class>mypac.myTag</tag-class>
       <body-content>jsp</body-content>
       <attribute>
           <name>color</name>
           <required>true</required>
           <rtexprvalue>true</rtexprvalue>
                  </attribute>
   </tag>
</taglib>
3.  Final step is to implement this tag like:
Code:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tlds/bodyTagLib.tld" prefix="m"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
    <h1>JSP Page</h1>
   
 <m:ashwani color="red">
     ashwani
     </m:ashwani>
        </body>
</html>
















Saturday, 31 August 2013

# create a multifile assembly


Þ    1.create a .cs file say <function.cs> which stores only static function.
Þ    2.create another file inside which you placed your main funtion say <hello.cs>(reference with namespace used if used.)
Þ    3. firstly , create a .net module: csc /t:module function.cs
Þ    4. secondly, csc /addmodule:function.netmodule /out:start.exe hello.cs


11:43 PM 28/08/2013

Tuesday, 20 August 2013

Display Image (path stored in database ) in gridView using Asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DisplayImages1.aspx.cs" Inherits="GrudViewImage.DisplayImages1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="image" HeaderText="image" SortExpression="image" />
                <asp:ImageField  DataImageUrlField="image" ControlStyle-Width="100"
        ControlStyle-Height = "100"  HeaderText = "Preview Image"/>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GridViewImageExampleConnectionString %>" SelectCommand="SELECT * FROM [GridViewImage]"></asp:SqlDataSource>
    </div>
    </form>
</body>
</html>