3
I tried to make a connection to the Mysql database using AsyncTask
, but is giving error in the class responsible for the connection, the MysqlConnect
:
The constructor Log() is not Visible
I’m following this tutorial and my problem is in the following excerpt from MysqlConnect
:
public MysqlConnect(Context context) {
this.context = context;
log = new Log();
}
My Mysqlconnect.java:
package br.com.alerts;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
public class MysqlConnect extends AsyncTask<Void, Void, Boolean> {
private static final String url = "jdbc:mysql://mysql.hostinger.com.br/u259053814_table";
private static final String user = "root";
private static final String pass = "root";
private Connection con;
private Log log;
private Context context;
private ProgressDialog dialog;
public MysqlConnect(Context context) {
this.context = context;
log = new Log();
}
public Boolean isConected() {
try
{
if (con == null)
{
return false;
} else {
return (!this.con.isClosed());
}
} catch (SQLException e) {
return false;
}
}
public String getLog() {
return log.toString();
}
public boolean connect() {
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, pass);
log.add("Conectado com sucesso!");
} catch(Exception e) {
e.printStackTrace();
}
return isConected();
}
public void disconnect() {
try {
con.close();
con.isClosed();
log.add("Desconectado!");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(this.context);
dialog.setMessage("Aguarde... conectando ao banco de dados...");
dialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
connect();
return isConected();
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
dialog.dismiss();
}
}
but as I adapt to my code?
– Jeiferson
remove or comment lines
log = new Log();
,private Log log;
and the functiongetLog
where you are using your variablelog
starts usingLog.d("","a sua mensagem");
– Icaro Martins
I’ll test here and give an opinion of the result..
– Jeiferson