Archive for November, 2008

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

Add a Row Dynamically using JavaScript

How to Add a Row Dynamically Using JavaScript:

  • We can see how button,textbox,textarea can be added Dynamically
  • All the tag which can be given in the input tag has to be given in setAttribute as shown in below coding
  • if u call a function then call as but1.onclick = function () {show(this)};
  • If u delete the Row,then reorder all the other row

1.If u Add a Button to a Table,then use this

var cell1 = row.insertCell(0);
but1 = document.createElement('input');
but1.setAttribute('type', 'button');
but1.setAttribute('className', 'button');
but1.setAttribute('value', '');
but1.onclick = function () {show(this)};
cell1.appendChild(but1);

2.If u Add a Textbox to a Table,then use this

 
var cell2 = row.insertCell(1);
var txt = document.createElement('input');
txt.setAttribute('type', 'text');
txt.setAttribute('name', 'firsttextbox');
txt.setAttribute('className', 'text_box');
txt.setAttribute('id', 'firsttextbox' + iteration);
txt.setAttribute('size', '21');
cell2.appendChild(txt);

3.If u Add a Textarea to a Table,then use this

cell1 = row.insertCell(1);
var e1 = document.createElement('textarea');
e1.name = 'text2' + iteration;
e1.id = 'text2' + iteration;
e1.column= '50';
cell1.appendChild(e1);

4.Row can be Re-Order by using

var tbl = delRow.parentNode.parentNode;
tbl.tBodies[0].rows[i].myRow.two.id = 'firsttextbox' + count;

If u Delete 3 Row the Reorder as
4th Row as—-3th Row
5th Row as—-4th Row
6th Row as—-5th Row

5.If u want to Delete the Third Row,then use this coding

 
var delRow = obj.parentNode.parentNode;
var rowArray = new Array(delRow);
for (var i=0; i&lt;rowObjArray.length; i++)</div>
{
  var rIndex = rowObjArray[i].sectionRowIndex;
  rowObjArray[i].parentNode.deleteRow(rIndex);
}
  • We have to pass all the id in the row as deleterow(this)
  • this can be get in the obj variable
  • Using the For Loop we have to Delete the Particular Row

Demo Link

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

Javascript compare two numbers

How to compare two Value in JavaScipts:

1.Get the Value From Html Page using getElementById

2.Compare by Using parseInt For Interger Value and parseFloat For Float Value

3.compare two value as

var first=document.getElementById('first').value;
var second=document.getElementById('second').value; 
 
if(parseInt(first)&lt;parseInt(second))
alert('Second Value is Greater than first');
 
else if(parseInt(first)&gt;parseInt(second))
alert('First Value is Greater than second');
 
else if(parseInt(first)==parseInt(second))
alert('First Value and second value is equal');

4.Include the code in Html Page For TextBox

First Value:<input type="text" value="0" onkeyup="compare();" name="first" id="first">
Second Value:<input type="text" value="0" onkeyup="compare();" name="second" id="second">

Demo Link

Popularity: 51% [?]

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

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

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

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