使用下表,如何将Guid值插入表的guidField中。使用以下常规代码将导致以下错误“因为:在这种情况下不允许使用名称“ B551F2C8”。生成的向导是B551F2C8-8380-491B-A51F-436E51CDD08F。也许Guid中的“-”是问题所在。有什么想法吗?
SQL表
create table tblTest
(
guidField uniqueidentifier,
strField varchar(50),
dateField smalldatetime
)
代码块
UUID uuid = UUID.randomUUID()
long lTimeStamp = d.getTime();
String tableInsert = "INSERT INTO tblTest (guidField,strField,dateField)" +
" VALUES (" + uuid +
"," + 'test' +
"," + lTimeStamp +
")";
sql.execute(tableInsert);
答案 0 :(得分:0)
UUID uuid = UUID.randomUUID()
//long lTimeStamp = d.getTime();
String tableInsert = "INSERT INTO tblTest (guidField,strField,dateField)" +
" VALUES ('" + uuid + "'"
",'test'" +
", getdate()"
")";
sql.execute(tableInsert);
在应用程序中需要向导吗?如果没有,请让SQL Server为您生成一个:
String tableInsert = "INSERT INTO tblTest (guidField,strField,dateField)" +
" VALUES (newid()"
",'test'" +
", getdate()"
")";
sql.execute(tableInsert);