javascript 从数据库字段输出多个TXT文件

hkstudio 2015-10-16 01:39:00
需求描述:利用javascript 连接 ORACLE,把assp_voucher表里voucher_no,voucher_no输出到txt文件里 ,assp_voucher一条记录输出 一个 txt文件,文件名以voucher_no命名。

下面是我写的代码,只能写一个。

大虾帮我 修改下,谢谢。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" defer="defer">
var strConnString = "Provider=OraOLEDB.Oracle;Data Source=evsdata;User ID=assp;Password=assp;PLSQLRset=1";
var conn = new ActiveXObject("ADODB.Connection");
conn.open(strConnString);
var rs = conn.execute("select * from assp_voucher");
document.all.voucher.value = "";
document.all.voucher_no.value = "";
while (!rs.EOF)
{
// alert(rs("voucher_no")+rs("voucher"));
// document.all.dbContent.value = document.all.dbContent.value + rs("voucher")+"/n";
document.all.voucher.value =rs("voucher")+"/n";
document.all.voucher_no.value =document.all.voucher_no.value + rs("voucher_no")+"/t";
//alert(rs("voucher_no"));
// document.getElementById("voucher").value=rs("voucher")
rs.moveNext;
}
rs.close();
conn.close();
conn = null;

//读文件
function readFile(filename){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename,1);
var s = "";
while (!f.AtEndOfStream)
s += f.ReadLine()+"/n";
f.Close();
return s;
}
//
//写文件
function writeFile(filename,filecontent){
var fso, f, s ;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(filename,8,true);
f.WriteLine(filecontent);
f.Close();
alert('write ok');
}

</script>
<title>无标题文档</title>
</head>
<body>
<textarea id="voucher" name="voucher" rows="10" cols="100"></textarea>
<textarea id="voucher_no" name="voucher_no" rows="5" cols="100"></textarea>
<input type="button" value="Write!" onclick="writeFile('c:/12.txt',document.getElementById('voucher').value);"/>
</body>
</html>
...全文
179 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hkstudio 2015-10-17
  • 打赏
  • 举报
回复
引用 4 楼 showbo 的回复:
[quote=引用 2 楼 xuangxing 的回复:] [quote=引用 1 楼 showbo 的回复:]
由于查出来的是base64加密后的字符串,在生成文件要进行解密,我写的没解成功,麻烦再帮忙 看下,谢谢. 由于base64解码比较 长无法上传代码. http://u.163.com/sRQYiJQ5 提取码: eCWg4kLE
  • 打赏
  • 举报
回复
引用 2 楼 xuangxing 的回复:
[quote=引用 1 楼 showbo 的回复:]

while (!rs.EOF) {
writeFile('c:\\' + rs("voucher_no") + '.txt', rs("voucher_no") + ' ' + rs("voucher"));/////////////////////
rs.moveNext;
}


var rs = conn.execute("select * from assp_voucher");

如何把select * from assp_voucher 这句sql 通过文本框输入,然后点 一下按钮才 生成 txt文件?[/quote]
你做个函数传入文本框输入的sql语句执行


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" defer="defer">
function executeSQL(sql){
var strConnString = "Provider=OraOLEDB.Oracle;Data Source=evsdata;User ID=assp;Password=assp;PLSQLRset=1";
var conn = new ActiveXObject("ADODB.Connection");
conn.open(strConnString);
var rs = conn.execute("select * from assp_voucher");
document.all.voucher.value = "";
document.all.voucher_no.value = "";
while (!rs.EOF) {
writeFile('c:\\' + rs("voucher_no") + '.txt', rs("voucher_no") + ' ' + rs("voucher"));/////////////////////
rs.moveNext;
}
rs.close();
conn.close();
conn = null;
}

//读文件
function readFile(filename){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename,1);
var s = "";
while (!f.AtEndOfStream)
s += f.ReadLine()+"/n";
f.Close();
return s;
}
//
//写文件
function writeFile(filename,filecontent){
var fso, f, s ;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(filename,8,true);
f.WriteLine(filecontent);
f.Close();
alert('write ok');
}

</script>
<title>无标题文档</title>
</head>
<body>
<textarea id="voucher" name="voucher" rows="10" cols="100"></textarea>
<textarea id="voucher_no" name="voucher_no" rows="5" cols="100"></textarea>
<input type="button" value="Write!" onclick="executeSQL(document.getElementById('voucher').value);"/>
</body>
</html>
hkstudio 2015-10-16
  • 打赏
  • 举报
回复
引用 1 楼 showbo 的回复:

    while (!rs.EOF) {
        writeFile('c:\\' + rs("voucher_no") + '.txt', rs("voucher_no") + '  ' + rs("voucher"));/////////////////////
        rs.moveNext;
    }
var rs = conn.execute("select * from assp_voucher"); 如何把select * from assp_voucher 这句sql 通过文本框输入,然后点 一下按钮才 生成 txt文件?
  • 打赏
  • 举报
回复

    while (!rs.EOF) {
        writeFile('c:\\' + rs("voucher_no") + '.txt', rs("voucher_no") + '  ' + rs("voucher"));/////////////////////
        rs.moveNext;
    }

87,984

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧