Popular Articles | Latest Articles | Categories | RSS Feeds

JSP Hit Counter Free Open Code

Published on 4/6/2007 by editor
More articles in JSP



 Vote this tutorial:

 

This counter uses MS SQL Server to store hits. I have used a custom stored procedure to add and display hit.  This is a very good example using stored procedures with JSP.

You may use this script only with MS SQL. First you should create a table and a procedure. You may use Query Manager.

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[counter]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[counter]
GO

CREATE TABLE [dbo].[counter] (
 [hit] [int] NOT NULL
) ON [PRIMARY]
GO
INSERT [dbo].[counter] (hit) VALUES (1)
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[webcounter]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[webcounter]
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

CREATE PROCEDURE dbo.webcounter
AS
BEGIN
SET NOCOUNT ON
DECLARE @hits INT
update counter set hit = hit + 1
SELECT hit from counter
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Now you can create our script. You may put this code anywhere you want to display the counter :

<%@ page import="java.sql.*" %>
<%
  Connection ocon = null;
  Class.forName("com.inet.tds.TdsDriver").newInstance();
  ocon = DriverManager.getConnection("jdbc:inetdae7:localhost", "sa", "");
  ocon.setCatalog( "dotnet" );

  Statement stmtt = ocon.createStatement();
  ResultSet rc = stmtt.executeQuery("EXEC dbo.webcounter");
  rc.next();
  int pages = rc.getInt(1);
  out.println("Hits : " + pages + "
");
%>


I have used i-net MERLIA JDBC driver.  


Comments:
no comments submitted


Only members can write comments.Please, login / register to write comment.

Latest Posts

Active News Manager - news management system




Welcome to Dotnetindex.com:Login  |  Register
Free software:
Giga RSS Reader
IkonAdman
QMailing list
Active News
Download Manager (PRO)
Download Manager (Lite)

Search Dotnetindex.com:


Who's online

  • There 17 online users.

Latest tutorialsAutocomplete Filter from the Old Futures Project Working in Dynamic Data 4
Developing a Facebook Connect Application Using ASP.NET
Conditional Row Highlighting in Dynamic Data
UserControl as a DLL Made Easy
Using GroupTemplate in ASP.NET ListView Control (Tiled Display)
Creating Master-Detail GridView Using jQuery
ASP.NET MVC 2.0 and AJAX Part 1
Sorting Tabular Data in ASP.NET MVC
Asynchronous Form in ASP.NET MVC 2
Populating ASP.NET TreeView Control Recursively
A look at SAP Crystal Reports for Visual Studio 2010
Reporting in Threads
Regular Expressions Make Pattern Matching and Data Extraction Easier
Perform Database Administration Operations with SQL Server Management Objects
SQL Server Compact 3.5 Beta 2 available for download
ASP.NET Resources, Reviews

ASP Resources, Reviews

PHP, ASP, .NET, JSP Resources, Reviews

Hotscripts.com Free Photoshop, Flash and 3DS MAX tutorials