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 tutorialsIntroduction to Dependency Injection Using StructureMap
SEO For ASP.NET Web Site
Using ASP.NET 3.5's ListView and DataPager Controls: The Ultimate DataPager Interface
Using jQuery To Hijack ASP.NET MVC Form Posts
Accessing and Updating Data in ASP.NET: Filtering Data Using a CheckBoxList
Predictive Fetch with jQuery and the ASP.NET Ajax Library
Building ASP.NET Web Forms to Use a MySQL Database
A Guide to Upgrading Your XP Machine for Optimum Performance with Windows 7
Retrieving Data from Microsoft SQL Server 2008 Using ASP.NET 3.5
Creating an ASP.NET Dynamic Web Page Using MS SQL Server 2008 Database (GridView Display)
Inserting Data into a Microsoft SQL 2008 Database in ASP.NET 3.5
Using C#, ASP.NET, and ADO.NET To Develop A Multi-Tier App From Start To Finish
URL Routing in ASP.NET 4.0
Integrating Twitter Into An ASP.NET Website
Creating Multiple Choice Exam Application Using ASP.NET MVC Framework
ASP.NET Resources, Reviews

ASP Resources, Reviews

PHP, ASP, .NET, JSP Resources, Reviews

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