Jalalazad
Jalalazad

Reputation: 21

Boolean error (Required Boolean ) in java

When the class conector.conexion(); if I use the command:

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

What is wrong?

Upvotes: 0

Views: 138

Answers (2)

Bhuwan Prasad Upadhyay
Bhuwan Prasad Upadhyay

Reputation: 3056

Connection is not Boolean type class. Instead of if(conector.conexion()) you can use like below :

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

Upvotes: 1

user3145373 ツ
user3145373 ツ

Reputation: 8146

Do following to check if connection instance has been created or not:

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

Upvotes: 0

Related Questions