Archive for the ‘Programming’ Category

Function To Generate Random Password using C#

usually you would send a random generated password while user does the registration process through your application.You can use the following code to achieve that.

public string Generate_Password()
{
string Password = “”;
byte Cnt, Idx;
string values = “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
Random rnd = new Random();
for (Cnt = 1; Cnt <= 6; Cnt++)
{
Idx = (byte)rnd.Next(0, values.Length);
Password += values.Substring(Idx, 1);
}
return Password.Trim().ToUpper();
}

To Generate Random Password we have used the Random Class(Namespace:-System).To learn more about Random Class have a look at this MSDN LINK.

Popularity: 3% [?]

SQL Server Connection Using Integrated Security

When we are connecting sql server using windows authentication then we do not need to give the user name and pwd in the connection string. We have to provide the Integrated Security property to true.

SqlConnection con = new SqlConnection(“Server=servername;Integrated Security=true; Database=emp”);

Note : If your sql server is of windows authentication and if you dont provide Integrated Security you may get an error such as follows
Login failed for user ‘(null)’. Reason: Not associated with a trusted SQL Server connection.

Popularity: 1% [?]

What is Delegate?

A delegate is a type that references a method.Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method,with parameters and a return value.

Any method that matches the delegate’s signature,which consists of the return type and parameters,can be assigned to the delegate.

Delegates allow methods to be passed as parameters.It can be used to define callback methods.

Popularity: 1% [?]

What is ViewState ?

ASP.NET view state is the technique used by an ASP.NET Web page to persist
changes to the state of a Web Form across postbacks.That is when a form is submitted in ASP .NET, the form reappears in the browser window together with all form values.

The ViewState indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a <form runat=”server”> control.

Hidden field placed on each page would be something as this
< input type=”hidden” name=”__VIEWSTATE” value=”CEbzzzEnmmz+Bc8IDFlnpgCLJ/HB00.” >
Maintaining the ViewState is the default setting for ASP.NET Web Forms. If you want to NOT maintain the ViewState, include the directive l%@ Page EnableViewState=”false” %> at the top of an .aspx page or add the attribute EnableViewState=”false” to any control.

Popularity: 1% [?]

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: 2% [?]

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: 1% [?]

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% [?]

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