LoginSignup
0
0

More than 3 years have passed since last update.

Rails6MSAccess

Last updated at Posted at 2021-04-17

Rails6とMSAccessの接続テスト(OK)

https://github.com/JFLABO/Rails6MSAccess

Microsoft Access Driver (*.mdb, *.accdb) is the name of Microsoft's ODBC driver for Microsoft Access. It is only available for Windows.

require 'dbi'
require "nkf"
def to_sjis(str)
str ? NKF.nkf('-s', str) : ""
end
def to_utf8(str)
str ? NKF.nkf('-w', str) : ""
end
def create_database_handle
# プログラムでODBCの接続文字列を指定する場合
# 上:ローカルドライブ、下:ネットワーク越しの書き方
# dsn = %q(DBI:ODBC:Driver={Microsoft Access Driver (.mdb, *.accdb)};Dbq=c://db/Sample.accdb;)
# dsn = %q(DBI:ODBC:Driver={Microsoft Access Driver (
.mdb, .accdb)};Dbq=//127.0.0.1/db/Sample.accdb;)
dsn = %q(DBI:ODBC:Driver={Microsoft Access Driver (
.mdb, *.accdb)};Dbq=j://sample.accdb;)

DBI.connect(dsn)

end

sql = "SELECT * From lins"
dbh = create_database_handle
sth = dbh.prepare("SELECT * from links")
sth.execute()   

while row = sth.fetch do
print "Message", "\n";
print "-------------------\n";
print to_utf8(row["title"])
end
sth.finish
dbh.disconnect

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0