To play with excel file through ruby, you have to insatll a gem.
> gem install 'parseexcel'
Now you need to require 'parseexcel'
so you code will look like:
as we know excel looks like a book where multiple pages exists.
so we have to create an instances accordingly.
so another snippet says:
like wise we can traverse through every worksheet.
enjoy working with excel.
cheers!
Wednesday, June 17, 2009
Friday, June 5, 2009
Mysql connectivity in ruby while database is allocated at LINUX machine
db = Mysql.real_connect(ip, Username, password, database_name)
username is that user which has all the privileges from mysql(CRUD).
now we should handle some exception handling to this code of line.
begin
# connect to the MySQL server
db = Mysql.real_connect(ip, Username, password, database_name)
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
end
oops! i forgot to require mysql file. obviously, i have to know the address where i am going to kill the real culprit.
so gusy require "mysql"
so lets go to attain the purpose of doing that mysql connectivity.
insertion of data into a specific table:
db.query("insert into table_name values(x,yz1,'For testing',null)")
edit a perticular record of a perticular table:
db.query("update table_name set column_1 = NULL , column_2 = NULL where Column_3 = 1")
deletion of a record of a perticular table:
db.query("DELETE from table_name where id > 2")
username is that user which has all the privileges from mysql(CRUD).
now we should handle some exception handling to this code of line.
begin
# connect to the MySQL server
db = Mysql.real_connect(ip, Username, password, database_name)
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
end
oops! i forgot to require mysql file. obviously, i have to know the address where i am going to kill the real culprit.
so gusy require "mysql"
so lets go to attain the purpose of doing that mysql connectivity.
insertion of data into a specific table:
db.query("insert into table_name values(x,yz1,'For testing',null)")
edit a perticular record of a perticular table:
db.query("update table_name set column_1 = NULL , column_2 = NULL where Column_3 = 1")
deletion of a record of a perticular table:
db.query("DELETE from table_name where id > 2")
Subscribe to:
Posts (Atom)