我有MSSQL DB,它是SQL_Latin1_General_CP1_CI_AS整理并填写了一些波斯语值, DB中存储的字段类型是String(nvarchar(50),null) 我想获取此String的ID,即Integer。 所以我打开我的连接并在我的代码中写这个:
ConnectionHelper connectionHelper = new ConnectionHelper();
statement2 = connectionHelper.getConnection().createStatement();
setType();
ResultSet resultSet = statement2.executeQuery("select Id from tblProductCategory where Name='" + getType() + "'");
但我不能。 getType()从我的GridView中返回persion中的字符串。
几小时后,我在我的tblProductCategory中插入拉丁字符串并选择其ID,并且它正常工作。我的问题是波斯语。 我搜索并发现mssql服务器没有utf-8,但是nvarchar支持这个。 任何想法?
答案 0 :(得分:0)
我找到了解决方案。
我必须在我的String之前插入N.It表示我的查询更改为:
ResultSet resultSet = statement2.executeQuery("select Id from tblProductCategory where Name=N'" + getType() + "'");