Tuesday, May 3, 2011

RUBY

Program For Reverse String



class Reverse
puts "Enter the number"
a=gets.chomp.to_i
while a>0
b=a%10
print b
a=a/10
end
end


//Fibonacci series

class Fibo
puts "enter the number"
a=gets.chomp.to_i
f1=0
f2=1
f3=1
puts "Fabonacci series upto numbers #{a+3}"
puts f1
puts f2
for i in 1..a
puts f3

f1=f2
f2=f3
f3=f1+ f2
end
puts f3
end


// FACTORIAL
class Fact
puts "Enter the number "
a=gets.chomp.to_i
c=1
if a==0
puts "the value of fact:#{c}"
end
if a>0
for fact in 1..a-1
a=a*fact
end
puts "the value of fact:#{a}"
end
end

//n TIMES
class Times
n=10
n.times{|i| print i}
end
// print string
class String
str= ["hello", "you", " are " , "welcomed" , " to", "mumbai" ]
for prt in 0...str.length
print prt,":" , str[prt],"\n";
end
end

//switch case
class Result
grade =9
school = case grade
when 5
"B"
when 8
"A"
when 9
"EX"
else
"college"
end
puts "grade #{grade} is in #{school}"
end

// KIND
class Each
gbu=%w( SICT SBT SMBA SS )
gbu.each{|kind| print kind}
end

CONNECT JAVA to MYSQL USING ODBC:

import java.sql.*;
public class Mysqlc
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mysqljava", "root","123" );
Statement s = con.createStatement();
s.executeQuery("SELECT * FROM pet");
ResultSet rset=s.getResultSet();

while(rset.next())
{System.out.println(rset.getString("name"));

}
}
catch(ClassNotFoundException exp)
{
System.err.println(exp);
}
catch(SQLException exp)
{System.err.println(exp);
}
}
}

Saturday, April 23, 2011

HOW TO INSTALL RAILS IN WINDOWS XP

you should have internet connection
After the installation of RUBY from previous post Follow some steps
set the ENVIRONMENT VARIABLE PATH OF RUBY
Download "rubygem-1.3.4.zip" or any version from given link:

rubygems



Extract rubygem .zip file and putt it in System Directory(C)
After that open CMD and go into "rubygem-1.3.4" directory Or what ever rubygem version you downloaded

C:\cd rubygems-1.3.4 press enter
C:\rubygems-1.3.4>ruby setup.rb press enter
Installing RubyGems
Installing gem executable
Removing old source_cache files
Removing old RubyGems RDoc and ri
Installing rubygems-1.3.4 ri into c:/ruby/lib/ruby/gems/1.8/doc/rubygems-1.3.4/r
i
Installing rubygems-1.3.4 rdoc into c:/ruby/lib/ruby/gems/1.8/doc/rubygems-1.3.4
/rdoc

------------------------------------------------------------------------------

Oh-no! Unable to find release notes!

------------------------------------------------------------------------------

RubyGems installed the following executables:
c:/ruby/bin/gem

After that type(in C directory )
C:\>gem install rails --version 2.3.2 --include-dependencies press enter

If you have a proxy internet connection then you will find an error
INFO: `gem install -y` is now default and will be removed
INFO: use --ignore-dependencies to install only the gems you list
ERROR: http://gems.rubyforge.org/ does not appear to be a repository
ERROR: could not find gem rails locally or in a repository

then type
C:\>SET HTTP_PROXY=http://USERNAME:PASS@HOST:PORT press enter
For example
C:\>SET HTTP_PROXY=http://ANDY8286:HELLO@172.25.5.6:3128
where PORT=3128
USERNAME=ANDY8286
PASSWORD=HELLO
HOST=172.25.5.6
AND THEN TYPE(you can choose a version which is available)
C:\>gem install rails --version 2.3.2 --include-dependencies press enter

then you will find messages(it will take few minutes)
INFO: `gem install -y` is now default and will be removed
INFO: use --ignore-dependencies to install only the gems you list
Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Successfully installed rails-2.3.2
7 gems installed
Installing ri documentation for rake-0.8.7...
Installing ri documentation for activesupport-2.3.2
'.
.
.
.



then follow these steps to create a directory
c:\> mkdir rails_apps press enter
c:\> cd rails_apps press enter
c:\rails_apps> cd demo press enter
c:\rails_apps>demo>ruby script\server press enter

your server will started.........

just open IE and type :http://localhost:3000


AND ENJOY RUBY ON RAILS ........

HOW TO INSTALL RUBY IN WINDOWS XP

How to install RUBY in windows xp

Download any version of rubyinstaller(.exe file) and then click on that .exe file and click on next next .......so on
Or follow this link

Ruby1.8.6


To check weather Ruby is installed or not .............

open command prompt and write "ruby -v" to check the version of ruby
For Example:

Friday, April 15, 2011

HOW TO CONNECT MS ACCESS DATABASE IN JAVA

Sample JAVA Program For MS ACCESS DATABASE connectivity

Create DATABASE in MS ACCESS then..........................

import java.sql.*;
public class Sample
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Data_Source_name", "username","password" );
Statement s = con.createStatement();
s.executeQuery("SELECT * FROM Table_name");
ResultSet rset=s.getResultSet();

while(rset.next())
{System.out.println(rset.getString("Column_name"));

}
}
catch(ClassNotFoundException exp)
{
System.err.println(exp);
}
catch(SQLException exp)
{System.err.println(exp);
}
}
}

where => "jdbc:odbc:Data_Source_name" represents URL of your database

Thursday, April 14, 2011

HOW TO INSTALL POSTGRESQL IN WINDOWS XP

HOW TO INSTALL POSTGRESQL IN WINDOWS XP

Download from :
Click Here to Download



After Download Follow This link:
PostgreSQL Installer Walkthrough



After Installation Follow These Steps:


STEP 1-


C:\Program Files\PostgreSQL\8.2\bin
C:\Program Files\PostgreSQL\8.2\bin>psql -U postgres
Password for user postgres:postgres


Welcome to psql 8.2.3, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

Warning: Console code page (437) differs from Windows code page (1252)
8-bit characters may not work correctly. See psql reference
page "Notes for Windows users" for details.

postgres=#


OR STEP 2- To Set Environment Variables



Click on Start=>Control Panel(Switch to classic user View)=> System
A window will Prompt Then click On " Advanced " button and then select "Environmental Variables"
Set user variables :
Variable name : PATH
Variable Value: C:\Program Files\PostgreSQL\8.2\bin
click on ok and ok and ok .........