Archive for the ‘Programming’ Category

Java with Sql Server

How to Connect Java with Sql Server :

1.import sql package

2.Give all the Supporting class in class.forName

3.Give Ipaddress or Computer Name in dburl or in getConnection

4.Use 1433 port Number as Default Port.

5.Give Username and Password in getConnection

6.Open the Connection using createStatement

7.Execute the query String using executeQuery Statement

8.Fetch the Record one by one Using ResultSet

9.Close the Connection

import java.io.*;
import java.sql.*;
public class sqlserverConnection
{
public static String dburl=”jdbc:mysql://localhost:1433”;
public static String username=”admin”;
public static String pwd=”pass”;
public static Connection con=null;
public static Statement stmt=null;
public static ResultSet rs=null;

public static void main(String[] args)
{
try {

Class.forName( “com.microsoft.jdbc.sqlserver.SQLServerDriver” );
con=DriverManager.getConnection(dburl,username,pwd);
stmt=con.createStatement();
rs=stmt.executeQuery(”SELECT * FROM demo”);
while(rs.next())
{
String name=rs.getString(1);
}
}
catch(SQLException sqlExcp)
{
sqlExcp.printStackTrace();
}
}
}

Popularity: 1% [?]

Java with Mysql

How to Connect Java with Mysql:

1.import sql package

2.Give all the Supporting class in class.forName

3.Give Ipaddress or Computer Name in dburl or in getConnection

4.Give Username and Password in getConnection

5.Open the Connection using createStatement

6.Execute the query String using executeQuery Statement

7.Fetch the Record one by one Using ResultSet

8..mysqldemo is a schema name

9.Close the Connection

import java.io.*;
import java.sql.*;
public class MysqlConnection
{
public static String dburl=”jdbc:mysql://localhost/mysqldemo”;
public static String username=”root”;
public static String pwd=”root”;
public static Connection con=null;
public static Statement stmt=null;
public static ResultSet rs=null;

public static void main(String[] args)
{
try {

Class.forName(”org.gjt.mm.mysql.Driver”);
(or)
Class.forName(”com.mysql.jdbc.Driver”);//use this

con=DriverManager.getConnection(dburl,username,pwd);
stmt=con.createStatement();
rs=stmt.executeQuery(”SELECT * FROM demo”);
while(rs.next())
{
String name=rs.getString(1);
}
}
catch(SQLException sqlExcp)
{
sqlExcp.printStackTrace();
}
}
}

Popularity: 1% [?]

Database Configuration in CakePHP

Step 1: Open the directory “/root/app/config/”
Step 2: Rename the “database.php.default” into “database.php”
Step 3: Open the file, that contain the default variable as shown below. Change the array variable values

var $default = array(‘driver’ => ‘mysql’,
‘connect’ => ‘mysql_connect’,
‘host’ => ‘localhost’,
‘login’ => ‘user’,
‘password’ => ‘password’,
‘database’ => ‘project_name’,
‘prefix’ => ”);

driver : This can be mysql, postgres, sqlite, adodb or pear-drivername
connect : should use persistent database connections. For mysql this options are ‘mysql_pconnect’ or ‘mysql_connect’
host : name of your database server, such as localhost / mysql.domainname.com
login : user name for your database login
password : password for your database login
database : name of the database
prefix : The string that prefixes every table name in the database. If your tables don’t have prefixes, this to an empty string.
Step 4: Save and close the file.

Popularity: 1% [?]

Taglibs in JSP

Different Taglibs and its Usuage in JSP:

1.Core:http://java.sun.com/jsp/jstl/core
This Taglibs is used for Looping,Variable Support,Flow control,URL Management and miscellaneous

<%@taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%>

2.XML:http://java.sun.com/jsp/jstl/xml
This Taglibs is Used for Core,Flow Control and Transformation

<%@taglib uri=”http://java.sun.com/jsp/jstl/xml” prefix=”xl”%>

3.Internationalization:http://java.sun.com/jsp/jstl/fmt
This Taglibs is Used For Locale, Message formatting and Number & date formatting

<%@taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt”%>

4.SQL:http://java.sun.com/jsp/jstl/sql
This Taglibs is Used For Sql Query Purpose

<%@ taglib uri=”http://java.sun.com/jsp/jstl/sql” prefix=”sql”%>

5.Functions:http://java.sun.com/jsp/jstl/functions
This Taglibs is Used For Collection length and String manipulation

<%@ taglib uri=”http://java.sun.com/jsp/jstl/functions” prefix=”fn”%>

Popularity: 1% [?]

CakePHP Files and Folder Structure

When you unpack Cake on your server you will find four folders – app, cake, tmp and vendors. The cake folder is where the core libraries for Cake lay and you generally won’t ever need to touch them unless you want to do some customization to Cake itself.


The app
is where your application specific folders and files will go. The separation between the cake folder with the core libraries and the app folder make it possible for you to have many app folders sharing a single set of Cake libraries. This also makes it easy to update CakePHP: you just download the latest version of Cake and overwrite you current core libraries; No need to worry about overwriting something you wrote for your app.

The tmp directory is used for various Cake operations, such as baking (automatically creating new php files), caching, and logging.

You can use the vendors directory to keep third-party libraries in. You’ll learn more about vendors later.

The folders structure and their basic purposes:

— root (the root directory)

— — app (here’s where your application logic will go)

— — — config (application specific configurations)

— — — controllers (controllers go here)

— — — — components

— — — index.php

— — — models (models go here)

— — — plugins (third party apps – go here)

— — — views (view related files go here)

— — — — elements (small repeated layout items go here)

— — — — errors (error pages go here)

— — — — helpers (your home-based helpers go here)

— — — — layouts (page layouts go here)

— — — — pages (static content managed by PagesController go here)

— — — webroot (this directory as your webroot, and stick your public files in here)

— — — — css

— — — — files

— — — — img

— — — — js

— — cake (this is where the libraries are placed: Note: it’s best not to touch)

— — index.php

— — tmp (used for logs, baking, etc.)

— — vendors (stick your third party libraries here)


Popularity: 2% [?]

How to Installing CakePHP?

Step 1 : Getting the most recent stable version
To install Cake PHP you first need to download the latest stable version from the CakePHP website at www.cakephp.org, once at the website click on Downloads > Release.
Download link : http://cakephp.org/downloads/index/nightly/1.2.x.x

Step 2: Unpacking
Now that you’ve downloaded the most recent release, place that compressed package on your web server in the webroot. Now you need to unpack the CakePHP package. There are two ways to do this, using a development setup, which allows you to easily view many CakePHP applications under a single domain, or using the production setup, which allows for a single CakePHP application on the domain.

Popularity: 1% [?]

Features of CakePHP

Like Rails, CakePHP makes it easier for the user to interface with the database with active records. It also encourages use of the model-view-controller architectural pattern.

  • Active, friendly community
  • Flexible licensing
  • Compatible with PHP4 and PHP5
  • Integrated CRUD(Create, Read, Update & Delete) for database and simplified querying
  • MVC architecture
  • Request dispatcher with clean, custom URLs and routes
  • Built-in validation
  • Templating (PHP syntax with helper methods)
  • View Helpers for AJAX, JavaScript, HTML Forms and more
  • Email, Cookie, Security, Session, and Request Handling Components
  • Flexible Access Control Lists (ACL)
  • Application scaffolding
  • Data sanitization
  • Flexible caching
  • Localization
  • Works from any web site directory, with little to no Apache configuration involved

Popularity: 2% [?]

History of CakePHP

CakePHP started in 2005, when Ruby on Rails was gaining popularity. The community has since grown and spawned several sub-projects. CakePHP is not a port of Ruby on Rails to PHP, but appropriates many of its useful concepts.

The Mambo Foundation announced in 2007 that it would utilize the CakePHP framework for future versions of its widely used content management system, calling CakePHP a “solid choice and certainly one of the top frameworks available today.”

Popularity: 1% [?]

What is CakePHP?

CakePHP is a free, open source, rapid development framework written in PHP. A structure of libraries, classes and run-time infrastructure for programmers creating web applications inspired originally by Ruby on Rails framework. The primary goal is to enable you to work in a structured and rapid manner–without loss of flexibility.

Popularity: 2% [?]

Create a Stored Procedure within a Stored Procedure

When you want to create a stored procedure dynamically,we can create a stored procedure within a stored procedure.

CREATE PROC procCreateProcedure
(
@spname NVARCHAR(100)
)
AS
BEGIN
DECLARE @ProcedureName NVARCHAR(100)
DECLARE @Exe VARCHAR(8000)

/*setting the stored procedure name with spname passed*/

SET @ProcedureName = @spname

/*setting the stored procedure name with spname passed*/

/*Nothing will be done if procedure name is empty*/
IF LTRIM(RTRIM(@ProcedureName)) = ”
BEGIN
RETURN
END
/*Nothing will be done if procedure name is empty*/

/*Creating the stored procedure*/

SET @Exe = ‘CREATE PROC ‘ + @ProcedureName + CHAR(13) +

‘AS’ + CHAR(13) + CHAR(13) +

‘BEGIN’ + CHAR(13) +

‘SELECT * FROM EMPLOYEE’+ CHAR(13) +

‘END’

/*Creating the stored procedure*/

/*Executing the created stored procedure*/
EXEC(@Exe)
/*Executing the created stored procedure*/

END

/*Executing procCreateProcedure to creat new stored procedure*/
EXEC procCreateProcedure ‘procTest’
/*Executing procCreateProcedure to creat new stored procedure*/

now execute and see the stored procedure by name you passed.

EXEC procTest

Here in this example a new stored procedure with name ‘procTest’ which is passed in ‘procCreateProcedure’ is created and employee table is fectched when ‘procTest’ stored procedure is executed.

Popularity: 1% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars