MySQL 使用“IS NULL”而不是“NULL”,那么我如何绑定变量来实现相同的效果?
现在我试着用这个
selectStmt.setNull( 2, java.sql.Types.VARCHAR );
当我打印“java.sql.Types.VARCHAR”时显示值 = 12?如果是这样,这如何在preparedstatment 中设置“IS NULL”?
更多细节:
即如果我在输入中有字符串=“”,我有兴趣查询(MySQL)是否为空。所以逻辑是这样的,
Connection c = SQLCon.connect();
PreparedStatement selectStmt = c.prepareStatement( "select * from "
+ TableName
+ " where P = ? AND M = ? AND PR = ? AND DR = ? " );
if ( P.trim().equals( "" ) )
{
selectStmt.setNull( 1, java.sql.Types.VARCHAR );
} else
{
selectStmt.setString( 1, P );
}
if ( M.trim().equals( "" ) )
{
selectStmt.setNull( 2, java.sql.Types.VARCHAR );
} else
{
selectStmt.setString( 2, M );
}
请指教