The data types varchar(max) and text are incompati

2019-09-11 19:17发布

while(rs.next())
{
    String key=rs.getString(1);
    String val=rs.getString(2);       
    it=ar1.get(k).toString();
    if(it.trim().equals(key.trim()))   
    {
        val=val.substring(1);
        val=val+"1";
    }
    else
    {
        val=val.substring(1);
        val=val+"0";
    }

    st = con.prepareStatement("update win set seq=? where keyy=?");
    st.setString(1,val);
    st.setString(2,key); //here i am getting exception
    st.executeUpdate();
    st.close();
}

if i change data type of seq and keyy in table as text then it shows The data types text and text are incompatible in the equal to operator

1条回答
啃猪蹄的小仙女
2楼-- · 2019-09-11 19:47

Haven't messed with TEXT data type in forever. But, leaving aside the questions about the wisdom of text "key" columns, you'll need to use like. You cannot use standard comparison operators on TEXT and NTEXT (=,<=, etc). You can leave out the wildcards, so it'll behave like an exact match. So if your keyy column is text:

update win set seq=? where keyy like ?

BTW, TEXT and NTEXT have been deprecated for several versions of SQL Server, I'm sure that one of these days they're going to drop it. You should probably look into converting to CHAR and VARCHAR.

查看更多
登录 后发表回答