关于SQLServerException: '' 附近有语法错误。的问题

bobo7605 2015-12-05 02:42:43
我导出了段脚本,在sqlserver里面执行没有问题,但在代码里面执行就提示 ,实在找不到,求救个位大神帮我看看,,
代码:
SQLExec sqlExec = new SQLExec();

// 设置数据库参数
sqlExec.setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");
sqlExec.setUrl(Tools.getCommonProp("Dbconnection") + ";DatabaseName=" + dbname);
sqlExec.setUserid(Tools.getCommonProp("Dbuser"));
sqlExec.setPassword(Tools.getCommonProp("Dbpwd"));
// 要执行的脚本
sqlExec.setSrc(new File(path));
// 有出错的语句该如何处理
sqlExec.setOnerror((SQLExec.OnError)(EnumeratedAttribute.getInstance(SQLExec.OnError.class, "abort")));

sqlExec.setPrint(false); // 设置是否输出
// 输出到文件 sql.out 中;不设置该属性,默认输出到控制台
//sqlExec.setOutput(new File("sql/sql.out"));
sqlExec.setProject(new Project()); // 要指定这个属性,不然会出错
sqlExec.execute();


sql脚本:

SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[picinfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[picinfo](
[id] [varchar](36) NOT NULL,
[piccode] [varchar](50) NULL,
[picpath] [varchar](5000) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[remark] [varchar](500) NULL,
CONSTRAINT [PK_PICINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AreaInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AreaInfo](
[id] [varchar](36) NOT NULL,
[areacode] [varchar](50) NULL,
[areaname] [varchar](50) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[remark] [varchar](500) NULL,
CONSTRAINT [PK_AREAINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BaseItemInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BaseItemInfo](
[id] [varchar](36) NOT NULL,
[goodname] [varchar](50) NULL,
[standardid] [varchar](36) NULL,
[barcode] [varchar](100) NULL,
[varietyid] [varchar](36) NULL,
[unitid] [varchar](36) NULL,
[producingarea] [varchar](500) NULL,
[produceddate] [datetime] NULL,
[expirationdate] [int] NULL,
[goodpicid] [varchar](36) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[remark] [varchar](500) NULL,
CONSTRAINT [PK_BASEITEMINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BillDetailInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BillDetailInfo](
[id] [varchar](36) NOT NULL,
[goodsid] [varchar](36) NULL,
[articledescription] [decimal](18, 0) NULL,
[totalrent] [decimal](18, 0) NULL,
[count] [int] NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[remark] [varchar](500) NULL,
CONSTRAINT [PK_BILLDETAILINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BillInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BillInfo](
[id] [varchar](36) NOT NULL,
[billno] [varchar](50) NULL,
[toid] [varchar](36) NULL,
[fromid] [varchar](36) NULL,
[billstatus] [int] NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[billdetailid] [varchar](36) NULL,
[remark] [varchar](500) NULL,
CONSTRAINT [PK_BILLINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ClienteleInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ClienteleInfo](
[id] [varchar](36) NOT NULL,
[clienteleno] [varchar](50) NULL,
[clientelename] [varchar](100) NULL,
[areaid] [varchar](36) NULL,
[contacts] [varchar](50) NULL,
[telphoneno] [varchar](50) NULL,
[varietyid] [varchar](36) NULL,
[address] [varchar](500) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[reamrk] [varchar](500) NULL,
CONSTRAINT [PK_CLIENTELEINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ItemVariety]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ItemVariety](
[id] [varchar](36) NOT NULL,
[varietyname] [varchar](50) NULL,
[varietycode] [varchar](100) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[remark] [varchar](500) NULL,
CONSTRAINT [PK_ITEMVARIETY] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MerchantInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[MerchantInfo](
[id] [varchar](36) NOT NULL,
[merchantNo] [varchar](50) NULL,
[merchantname] [varchar](100) NULL,
[areaid] [varchar](36) NULL,
[contacts] [varchar](50) NULL,
[telphoneno] [varchar](50) NULL,
[varietyid] [varchar](36) NULL,
[address] [varchar](500) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[reamrk] [varchar](500) NULL,
CONSTRAINT [PK_MERCHANTINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[StandardInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[StandardInfo](
[id] [varchar](36) NOT NULL,
[standardcode] [varchar](50) NULL,
[standardname] [varchar](100) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[reamark] [varchar](500) NULL,
CONSTRAINT [PK_STANDARDINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
;
SET ANSI_NULLS ON
;
SET QUOTED_IDENTIFIER ON
;
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UnitInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UnitInfo](
[id] [varchar](36) NOT NULL,
[unitname] [varchar](50) NULL,
[createdate] [datetime] NULL,
[modifydate] [datetime] NULL,
[reamrk] [varchar](500) NULL,
CONSTRAINT [PK_UNITINFO] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
...全文
606 1 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
你可以这么试试,就是在代码里把先放一半的sql,看看会不会报错, 如果会报错,那说明这一半代码里有问题,然后再取其中的一半放到代码里,然后多试几次,应该就能找到问题。
回复
中国风 2015-12-05
SET ANSI_NULLS ON ; SET QUOTED_IDENTIFIER ON ; 全去掉再试试
回复
bobo7605 2015-12-05
引用 1 楼 roy_88 的回复:
在程序用sqlcommend去调用 建表最好在数据库里写个存储过程动态方法调用 在程序里直接建表,不能有效利用数据库性能,如索引创建等等
小型应用,希望简单解决
回复
中国风 2015-12-05
在程序用sqlcommend去调用 建表最好在数据库里写个存储过程动态方法调用 在程序里直接建表,不能有效利用数据库性能,如索引创建等等
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2015-12-05 02:42
社区公告
暂无公告