[英]Insert GUID into sql table uniqueidentifier field - Groovy
With the following table how would I insert a Guid value into the guidField of the table. 使用下表,如何将Guid值插入表的guidField中。 Using the following groovy code results in the following error "because: The name "B551F2C8" is not permitted in this context."
使用以下常规代码将导致以下错误“因为:在这种情况下不允许使用名称“ B551F2C8”。 Guid generated is B551F2C8-8380-491B-A51F-436E51CDD08F.
生成的向导是B551F2C8-8380-491B-A51F-436E51CDD08F。 Maybe the '-' in the Guid are the problem.
也许Guid中的“-”是问题所在。 Any ideas?
有任何想法吗?
SQL table SQL表
create table tblTest
(
guidField uniqueidentifier,
strField varchar(50),
dateField smalldatetime
)
Code block 代码块
UUID uuid = UUID.randomUUID()
long lTimeStamp = d.getTime();
String tableInsert = "INSERT INTO tblTest (guidField,strField,dateField)" +
" VALUES (" + uuid +
"," + 'test' +
"," + lTimeStamp +
")";
sql.execute(tableInsert);
UUID uuid = UUID.randomUUID()
//long lTimeStamp = d.getTime();
String tableInsert = "INSERT INTO tblTest (guidField,strField,dateField)" +
" VALUES ('" + uuid + "'"
",'test'" +
", getdate()"
")";
sql.execute(tableInsert);
Do you need your guid into your application? 您的应用程序需要向导吗? If not, let SQL server generate one for you :
如果没有,请让SQL Server为您生成一个:
String tableInsert = "INSERT INTO tblTest (guidField,strField,dateField)" +
" VALUES (newid()"
",'test'" +
", getdate()"
")";
sql.execute(tableInsert);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.