Hello, ADO(JScript) World!
Posted on 9月 16th, 2012 by cx20
ADO(JScript)
ADO(ActiveX Data Objects)は、マイクロソフト社が開発した COM ベースの DBMS 接続用 API である。
OLE DB プロバイダを介することで様々な DBMS への接続が可能となっている。
OLE DB プロバイダとしては、以下のようなプロバイダがある。いくつかが OS 標準で付属している他、追加インストールが可能である。
プロバイダ名 |
表示名 |
説明 |
MSDASQL |
Microsoft OLE DB Provider for ODBC |
ODBC データベース |
Microsoft.Jet.OLEDB.4.0 |
Microsoft OLE DB Provider for Microsoft Jet |
Microsoft Jet データベース |
Microsoft.ACE.OLEDB.12.0 |
Microsoft Office 12.0 Access Database Engine OLE DB Provider |
Microsoft Access データベース |
SQLOLEDB |
Microsoft OLE DB Provider for SQL Server |
Microsoft SQL Server |
SQLNCLI10 |
SQL Server Native Client 10.0 |
Microsoft SQL Server |
MSDAORA |
Microsoft OLE DB Provider for Oracle |
Oracle データベース |
ソースコード(JScript + ADO + OLEDB + Jet データベース)
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=.\hello.mdb" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
} |
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=.\hello.mdb" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
}
ソースコード(JScript + ADO + OLEDB + ACE データベース)
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=.\hello.accdb" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
} |
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=.\hello.accdb" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
}
ソースコード(JScript + ADO + OLEDB + SQL Server)
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=SQLOLEDB;SERVER=(local);DATABASE=master", "sa", "P@ssW0rd" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
} |
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=SQLOLEDB;SERVER=(local);DATABASE=master", "sa", "P@ssW0rd" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
}
ソースコード(JScript + ADO + OLEDB + Oracle)
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDAORA;Data Source=ORCL", "scott", "tiger" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
} |
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDAORA;Data Source=ORCL", "scott", "tiger" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
}
ソースコード(JScript + ADO + ODBC + SQL Server)
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDASQL;Driver={SQL Server};SERVER=(local);DATABASE=master", "sa", "P@ssW0rd" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
} |
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDASQL;Driver={SQL Server};SERVER=(local);DATABASE=master", "sa", "P@ssW0rd" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
}
ソースコード(JScript + ADO + ODBC + Oracle)
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDASQL;Driver={Microsoft ODBC for Oracle};Server=ORCL", "scott", "tiger" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
} |
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDASQL;Driver={Microsoft ODBC for Oracle};Server=ORCL", "scott", "tiger" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
}
ソースコード(JScript + ADO + ODBC + MySQL)
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDASQL;Driver={MySQL ODBC 5.1 Driver};Server=localhost", "root", "P@ssW0rd" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
} |
main();
function main() {
var cn = new ActiveXObject("ADODB.Connection");
cn.Open( "PROVIDER=MSDASQL;Driver={MySQL ODBC 5.1 Driver};Server=localhost", "root", "P@ssW0rd" );
var rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message");
while ( !rs.EOF )
{
WScript.Echo( rs(0).Name );
WScript.Echo( "-------------------" );
WScript.Echo( rs(0).Value );
rs.MoveNext();
}
rs.Close();
cn.Close();
}
実行方法(Windows)
C:¥> CScript //Nologo Hello.js |
C:¥> CScript //Nologo Hello.js
実行結果
Message
-----------------
Hello, ADO World! |
Message
-----------------
Hello, ADO World!
Tags: ADO
Categories: ADO, JavaScript