android - Java MySQL and JFrame connection "Cannot convert from boolean to connection" -


public class bancodedados {

static string url = "jdbc:mysql://localhost:3306/estoque"; static string pass = "admin"; static string user = "admin"; static connection conexao = null;  public static boolean conecta() throws classnotfoundexception {      try {         class.forname("mysql.driver");         conexao = drivermanager.getconnection(url, user, pass);         //system.out.println("conectado.");         joptionpane.showmessagedialog(null, "conectado com sucesso!");         return true;     } catch (sqlexception e) {         joptionpane.showmessagedialog(null, "usuário e/ou senha estão incorretos!");         //system.out.println("usuário e/ou senha estão errados.");         return false;     }  } 

public class telaprincipal extends jframe {

connection conexao = null; preparedstatement pst = null; resultset rs = null;   private jpanel contentpane; private jtextfield textlogin; private jpasswordfield textsenha;      public void logar(){     string sql = "select *from login usuario = ? , senha = ?";     try{         pst = conexao.preparestatement(sql);         pst.setstring(1, textlogin.gettext());         pst.setstring(2, textsenha.gettext());         rs = pst.executequery();          if(rs.next()){             telaopcoes telaopcoes = new telaopcoes();             telaopcoes.setvisible(true);             dispose();               }         else{             joptionpane.showmessagedialog(null, "usuário e senha inválidos");         }      }      catch(sqlexception error){         joptionpane.showmessagedialog(null, error);      } }   /**  * launch application.  */ public static void main(string[] args) {     eventqueue.invokelater(new runnable() {         public void run() {             try {                 telaprincipal frame = new telaprincipal();                 frame.setvisible(true);             } catch (classnotfoundexception e) {                 e.printstacktrace();             }         }     }); }  /**  * create frame.  */ public telaprincipal() throws classnotfoundexception {      conexao = bancodedados.conecta();     this.setlocationrelativeto(null); 

its doing error on penultimate line " conexao = bancodedados.conecta(); " saying "type mismatch : cannot convert boolean connection" can me please? thanks!

conexao = bancodedados.conecta();

here conexao connection variable

but method bancodedados.conecta(); returns boolean value.

so change type of variable conexao

or create new variable boolean type store result boolean conexao = bancodedados.conecta();


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -