Wednesday, August 27, 2008

New learnings in Java

1. There is no need to initialize static variable because by default it set variable value to zero, but when you use "final" keyword with static then you must have to initialize that variable with value, otherwise you will get compile time error

2. Only a class whose definition is complete can be declared as final, once you declare any class as final den after you cant be extend this class or you cant override any method also.

3. you cant instantiate class which is declared as abstract type

4. Final variable are known as "blank final variable" and "named constant"

5. abstract and final will never work together.

6. You cant declare transient variable inside methods

7. Sometime, Java used to cache variable value in the memory for efficiency purpose, which is not correct in the case of multi-threading. To avoid jvm to store variable value in the cache we can use "volatile" keyword.

8. You can not use final and volatile both at same time.

9. VirtualMachineError, LinkageError are going to handel by "Error" class

10. Each assetions contains boolean expression , if its reutn true when assertion is executed. if its return false, the system throws a special assertion type exceptions.

Where to find wsdl.exe file?

Easy :)

It will be at %HOME_DIR_OF_VISUALSTUDIO_INSTALLATION%\SDK\V2.0\BIN

Creating a Stored Procedure

You can create stored procedures using the CREATE PROCEDURE Transact-SQL statement. Before creating a stored procedure, consider that:

-> CREATE PROCEDURE statements cannot be combined with other SQL statements in a single batch.
-> Permission to create stored procedures defaults to the database owner, who can transfer it to other users.
-> Stored procedures are database objects, and their names must follow the rules for identifiers.
-> You can create a stored procedure only in the current database.
-> When creating a stored procedure, you should specify:
-> Any input parameters and output parameters to the calling procedure or batch.
-> The programming statements that perform operations in the database, including calling other procedures.
-> The status value returned to the calling procedure or batch to indicate success or failure (and the reason for failure).


System Stored Procedures
Many of your administrative activities in Microsoft® SQL Server™ 2000 are performed through a special kind of procedure known as a system stored procedure. System stored procedures are created and stored in the master database and have the sp_ prefix. System stored procedures can be executed from any database without having to qualify the stored procedure name fully using the database name master.

It is strongly recommended that you do not create any stored procedures using sp_ as a prefix. SQL Server always looks for a stored procedure beginning with sp_ in this order:
-> The stored procedure in the master database.
-> The stored procedure based on any qualifiers provided (database name or owner).
-> The stored procedure using dbo as the owner, if one is not specified.
-> Therefore, although the user-created stored procedure prefixed with sp_ may exist in the current database, the master database is always checked first, even if the stored procedure is qualified with the database name.

Important: If any user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.

Grouping
A procedure can be created with the same name as an existing stored procedure if it is given a different identification number, which allows the procedures to be grouped logically. Grouping procedures with the same name allows them to be deleted at the same time. Procedures used in the same application are often grouped this way. For example, the procedures used with the my_app application might be named my_proc;1, my_proc;2, and so on. Deleting my_proc deletes the entire group. After procedures have been grouped, individual procedures within the group cannot be deleted.

Temporary Stored Procedures
Private and global temporary stored procedures, analogous to temporary tables, can be created with the # and ## prefixes added to the procedure name. # denotes a local temporary stored procedure; ## denotes a global temporary stored procedure. These procedures do not exist after SQL Server is shut down.

Temporary stored procedures are useful when connecting to earlier versions of SQL Server that do not support the reuse of execution plans for Transact-SQL statements or batches. Applications connecting to SQL Server version 2000 should use the sp_executesql system stored procedure instead of temporary stored procedures. For more information, see Execution Plan Caching and Reuse.

Only the connection that created a local temporary procedure can execute it, and the procedure is automatically deleted when the connection is closed (when the user logs out of SQL Server).

Any connection can execute a global temporary stored procedure. A global temporary stored procedure exists until the connection used by the user who created the procedure is closed and any currently executing versions of the procedure by any other connections are completed. Once the connection that was used to create the procedure is closed, no further execution of the global temporary stored procedure is allowed. Only those connections that have already started executing the stored procedure are allowed to complete.

If a stored procedure not prefixed with # or ## is created directly in the tempdb database, the stored procedure is automatically deleted when SQL Server is shut down because tempdb is re-created every time SQL Server is started. Procedures created directly in tempdb exist even after the creating connection is terminated. As with any other object, permissions to execute the temporary stored procedure can be granted, denied, and revoked to other users.

WSDL to Java using Eclipse

Hi Friends,

I have spent almost 3 hours to find a way to convert wsdl to java and finally I have done it hence i am sharing my findings with all of you so atleast you can save your time.

1. Download eclipse if you do not have
2. Download org.apache.axis.wsdl2java.eclipse_1.1.0.1.zip , extract it and put it under plugins directory of eclipse installation.
3. Download org.apache.axis_1.1.zip , extract it and put it under plugins directory of eclipse installation.
4. Select a file container in eclipse (folder), right click to get pop-up menu and select Import



5. The first page of the import wizard will appear on screen. Select the Import WebService reference



6.Follow the instruction and press finish button

Tuesday, August 26, 2008

Optimizing the Display of Simple Tables

Microsoft’s ASP technology enables beginners to write dynamic web pages with little effort.The ADO object model hides the complexity of obtaining data from the database. However, hiding complexity under a simple interface also allows unsuspecting programmers to write wildly inefficient code. Consider the common task of querying the database and displaying the results in an HTML table.

One of the slowest methods is to loop through the recordset, and concatenate each row into a string. Once the loop is complete, the string is written to the response. Many novices may apply this technique due to its logical simplicity, or by following the bad example of others. However, for anything but very small data sets, this technique is highly innefficient. The next code example shows how this technique might be used.

SIMPLETABLEExample.ASP
========================

<%@ Language=VBScript %>
<% Option Explicit %>
Dim StartTime, EndTime
StartTime = Timer
Dim objCN ’ ADO Connection object
Dim objRS ’ ADO Recordset object
Dim strsql ’ SQL query string
Dim strTemp ’ a temporary string
’ Create a connection object
Set objCN = Server.CreateObject("ADODB.Connection")
’ Connect to the data source
objCN.ConnectionString = "DSN=datasource"
objCN.Open
’ Prepare a SQL query string
strsql = "SELECT * FROM tblData"
’ Execute the SQL query and set the implicitly created recordset
Set objRS = objCN.Execute(strsql)
’ Write out the results in a table by concatenating into a string
Response.write "<table>"
Do While Not objRS.EOF
strTemp = strTemp & "<tr><td>" & objRS("field1") & "</td>"
strTemp = strTemp & "<td>" & objRS("field2") & "</td>"
strTemp = strTemp & "<td>" & objRS("field3") & "</td>"
strTemp = strTemp & "<td>" & objRS("field4") & "</td></tr>"
objRS.MoveNext
Loop
Response.write strTemp
Response.write "</table>"
Set objCN = Nothing
Set objRS = Nothing
EndTime = Timer
Response.write "<p>processing took "&(EndTime-StartTime)&" seconds<p> "


Test Results Records Time
============= =============
1000 3.5 seconds
2000 18.4 seconds
10000 7.5 minutes (est.)
20000 30 minutes (est.)

The server processing time to display 1000 records from the table is about 3.5 seconds.Doubling the number of records to 2000 more than quadruples the time to 18.4 seconds. The script times out for the other tests, but some time estimates are given. In the code, the ’&’ concatenation operator is used heavily within the loop.

Concatenation in VBScript requires new memory to be allocated and the entire string to be copied. If the concatenation is accumulating in a single string, then an increasingly long string must be copied on each iteration. This is why the time increases as the square of the number of records. Therefore, the first optimization technique is to avoid accumulating the database results into a string.

Eliminating Concatenation From the Loop
Concatenation may be removed easily by using Response.write directly in the loop. (In ASP.Net, the StringBuilder class can be used for creating long strings, but Response.write is fastest.) By eliminating accumulation, the processing time becomes proportional to the number of records being printed, rather than being exponential.

Each use of the concatenation operator results in unnecessary memory copying. With larger recordsets or high-load servers, this time can become significant. Therefore, instead of concatenating, programmers should simply write out the data with liberal use of Response.write. The code snippet below shows that even a few non-accumulative concatenations cause a noticeable time difference when run repeatedly.

’ Using concatenation in a loop takes 1.93 seconds.
For i = 0 To 500000
Response.write vbTab & "foo" & vbCrLf
Next
’ Using multiple Response.write calls takes 1.62 seconds.
For i = 0 To 500000
Response.write vbTab
Response.write "foo"
Response.write vbCrLf
Next