怎么用JAVA做的 SWT 程序中调用 SQL脚本(有更好的方式也介绍下),执行后数据库,表,索引,权限等都建好了。
java.sql.BatchUpdateException: 未能在 sysdatabases 中找到数据库 'DigiTalDATA' 所对应的条目。没有找到具有该名称的条目。请确保正确地输入了名称。
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeBatch(Unknown Source)
本人用JAVA读取所有SQL,批量执行后就报上面错误。目前仅在SQL中测试
因为去掉GO或其它原因,未知??!!
ArrayList sqllist= loadsql(sqlfilepath);
conn.setAutoCommit(false);
stmt = conn.createStatement();
for (String sql : sqllist) {
stmt.addBatch(sql);
}
stmt.executeBatch();
给你参考下:
stmt=conn.createStatement();
stmt.executeUpdate("create database test");
stmt.executeUpdate("use test");
stmt.executeUpdate("create table test1(id INT not null primary key,name VARCHAR(20) not null,address VARCHAR(50) not null,email VARCHAR(20) not null");
stmt.addBatch("insert into bookinfo values(1,'1','2','3')");
stmt.executeBatch();
可能是你sql执行的顺序问题导致的吧,
这么初级的问题啊,自己一步一步查错,你把你的语句扔到数据库客户端能执行吗?