Sunday, 23 December 2012

Decimal value check code


<script type="text/javascript" language="javascript">
function isDecimal(str){
if(isNaN(str) || str.indexOf(".")<0){
alert("Invalid");
}
else{
str=parseFloat(str);
alert(str.toFixed(2))
alert ("Entered number is decimal")
}
}

function validate(){
var dec=document.form.num.value;
if (dec == ""){
alert("Please enter.");
form.num.focus();
return false;
}
if (isDecimal(dec)==false){
num="";
form.num.focus();
return false;
}
return true;
}
</script>
<form name="form" method="post" onsubmit="return validate();">
Enter Decimal Number:<input type="text" name="num"> <input
type="submit" value="Check">
</form>

Monday, 17 December 2012

Threads in java


class Thrchild implements Runnable
{
Thread t;
Thrchild()
{
t=new Thread(this,"Demo Thread");
System.out.println("Child Name"+t);
t.start();
}
public void run()
{
try
{
for(int i=1;i<=5;i++)
{
System.out.println("-->Child thread running"+i);
t.sleep(400);
}
}
catch(Exception e)
{
System.out.println("Exception in child"+e);
}
System.out.println("Child thread Completed");
}
}
public class Thrswitch {
public static void main(String arg[])
{
Thrchild tc=new Thrchild();
try
{
for(int i=1;i<=5;i++)
{
System.out.println("Main thread running"+i);
Thread.sleep(1000);
}
}
catch(Exception e)
{
System.out.println("Exception in main"+e);
}
System.out.println("Main thread Completed");
}
}

Tuesday, 4 December 2012

Adding a google map with your html document


<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script>
function initialize()
{
var mapProp = {
  center:new google.maps.LatLng(51.508742,-0.120850),
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };
var map=new google.maps.Map(document.getElementById("googleMap")
  ,mapProp);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:900px;height:780px;"></div>

</body>
</html>

Monday, 3 December 2012

Browsers back button diasable


Write the below code in your HTML body tag(in on load method)

<Script type="text/javascript">
   //window.history.forward();
    function noBack()
{
window.history.forward();
    }
</Script>



Steps for creating ASP.NET WebService


Procedure:[Web service]

Server:

File->New->Web Site->(Visual C#) ASP.Net Web Service

Press F5 and Run the application and Copy the URL

Client:

File->New->Project->(Visual C#) Console Application

Go to Solution Explorer-> Right Click on Reference->Choose Add Service Reference
               Paste the URL in Address Bar & Click Go Button
                                               
                                               
Sample code:[Server]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]

public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Everybody listen....";
    }
   
}

[Client]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace trial
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceReference.ServiceSoapClient gs = new ServiceReference.ServiceSoapClient();
            System.Console.WriteLine("Response message:"+gs.HelloWorld());
            System.Console.ReadLine();
        }
    }
}
                                                

Simple output display


public static void main(String args[])
{
int i=1;
int j;
while(i<=7){
for(j=1;j<=i;j++)
System.out.print("*");
i=i+2;
System.out.println("");
}
i=5;
while(i>=1){
for(j=1;j<=i;j++)
System.out.print("*");
i=i-2;
System.out.println();
}
}


Output:


*
***
*****
*******
*****
***
*


Monday, 5 November 2012

Simple connection string


try
        {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:Test");
        String sql = "Select * from login";
        java.sql.Statement stmt =  con.createStatement();
        ResultSet rs = stmt.executeQuery( sql );
        while(rs.next())
        {
            String username=rs.getString("uname");
            String pasword=rs.getString("pword");
            System.out.println(username);
            System.out.println(pasword);
        }
        }
        catch(Exception e)
        {
           
        }

DBT - Models

Models are where your developers spend most of their time within a dbt environment. Models are primarily written as a select statement and ...