Raistlin
Raistlin

Reputation: 427

JDBC on SQL Server, executeQuery() cannot find the result with null

I use jdbc to retrieve data from SQL Server, and ANSI_NULLS is off . So if I run

select * from cj_log where evt = null

I can get the result.

But when I put it in a statement like this

Statement st = DBConnection.getConnection().createStatement();
String sql = "select * from CJ_LOG where EVT=null";
ResultSet rs = st.executeQuery(sql);

The result set is empty. What is the problem here?

Upvotes: 1

Views: 532

Answers (1)

Ben
Ben

Reputation: 35613

You need to say

where EVT is null

Nothing is ever equal to null, even null.

Think of it like this: Null means "don't know".

You are asking "is something I don't know equal to something I don't know"

The answer is "I don't know". So you don't get any rows.

Upvotes: 2

Related Questions