java文件中columm错误找不到,使用JDBC java更改MDB文件中的列名

I am currently writing a mdb Migration script in Java. This is noting but adding and modifying some of the column names in the MDB file.

I created new tables and thats not a problem but I could not find a query to Alter the name of the column

Lets say I have table named Employees having columns as "ID", "EName", "Active?" Now I want to change the column name "Active?" to "Active" (i.e. without question mark.)

How this can be done using JDBC java.

THanks

解决方案

One way to accomplish your goal would be to save the following VBScript code as RenameColumn.vbs...

Option Explicit

Dim objArgs, dbPath, tblName, oldColName, newColName

Dim dbe ' As DAO.DBEngine

Dim db ' As DAO.Database

Dim fld ' As DAO.Field

Set objArgs = WScript.Arguments

dbPath = objArgs(0)

tblName = objArgs(1)

oldColName = objArgs(2)

newColName = objArgs(3)

Set dbe = CreateObject("DAO.DBEngine.120")

Set db = dbe.OpenDatabase(dbPath)

Set fld = db.TableDefs(tblName).Fields(oldColName)

fld.Name = newColName

Set fld = Nothing

Set db = Nothing

Set dbe = Nothing

...and then your Java program could invoke it using code something like this:

import java.io.*;

public class RenameColumns {

public static void main(String[] args) {

String dbPath = "C:\\__tmp\\Database1.accdb";

String tblName = "Employees";

String oldColName = "Active?";

String newColName = "Active";

String cmd =

"cscript C:\\__tmp\\RenameColumn.vbs"

+ " \"" + dbPath + "\""

+ " \"" + tblName + "\""

+ " \"" + oldColName + "\""

+ " \"" + newColName + "\"";

try {

Process p = Runtime.getRuntime().exec(cmd);

p.waitFor();

BufferedReader rdr =

new BufferedReader(new InputStreamReader(p.getErrorStream()));

int errorLines = 0;

String line = rdr.readLine();

while (line != null) {

errorLines++;

System.out.println(line); // display error line(s), if any

line = rdr.readLine();

}

if (errorLines == 0) {

System.out.println("The operation completed successfully.");

}

} catch(Exception e) {

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值