简体   繁体   English

Java中的布尔错误(必需的Boolean)

[英]Boolean error (Required Boolean ) in java

When the class conector.conexion(); 当类conector.conexion(); if I use the command: 如果我使用命令:

if (conector.conexion()) {
}
Error : Required Boolean  `conector.conexion()`

What is wrong? 怎么了?

Connection is not Boolean type class. 连接不是布尔类型类。 Instead of if(conector.conexion()) you can use like below : 代替if(conector.conexion())您可以像下面这样使用:

if(conector.conexion() != null) {
  //It ensure connection is not null
  //To check connection is not closed
  if(!conector.conexion().isClosed()) {
   //code...
  } 
}

For Detail: Connection Docs 有关详细信息: 连接文档

Do following to check if connection instance has been created or not: 请执行以下操作检查连接实例是否已创建:

if(conector.conexion() != null){
     //code stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM