The data types varchar(max) and text are incompatible in the equal to operator. in SQL Server2005 how to solve?

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

  • Perl - DBI string incorrectly gets double quoted
  • Subscribe to event of an object which is not yet created?
  • Why don't connect android to database directly?
  • When a SQL job starts, what is the value of @@ROWCOUNT?
  • Denormalizing Data (Maybe A Pivot?)
  • MS SQL : Full Text Search Results are not relevant
  • SQL Server Coalesce condition
  • SQLCLR Stored procedure datatypes
  • Without installing SQL Server, .net application which inserts data can run on the machine?
  • Merge and When Matched query giving an error sql server
  • SQL Server INLINE IF ELSE
  • “Failed to retrieve the server version” error when connecting to SQL Server
  • One Solution collect form web for “The data types varchar(max) and text are incompatible in the equal to operator. in SQL Server2005 how to solve?”

    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.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.