I am making an application in the company where I can do registration of condominiums and visitors of the place. I am making a connection to the SQL Server 2008 database quietly, but I can not do the CRUD in the application. I made the Add test a condominium, but when I hit the "Save" button, the ProgressBar just keeps running and nothing happens.
public class MegaPermanentes extends AppCompatActivity {
//Declarando as variáveis //
ConnectionClass connectionClass;
EditText editName, editDocument;
Button addButton, editButton, deleteButton;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mega_permanentes);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
connectionClass = new ConnectionClass();
editName = (EditText) findViewById(R.id.edtName);
editDocument = (EditText) findViewById(R.id.edtDocumento);
addButton = (Button) findViewById(R.id.addButton);
editButton = (Button) findViewById(R.id.editButton);
deleteButton = (Button) findViewById(R.id.removeButton);
progressBar = (ProgressBar) findViewById(R.id.progBar);
progressBar.setVisibility(View.GONE);
addButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick (View v){
AddInfo addPro = new AddInfo();
addPro.execute("");
editName.setText("");
editDocument.setText("");
}
});
}
public class AddInfo extends AsyncTask<String, String, String>{
String z = "";
Boolean isSucess = false;
String infoName = editName.getText().toString();
String infoDocu = editDocument.getText().toString();
@Override
protected void onPreExecute()
{
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected String doInBackground(String... params) {
if(infoName.trim().equals("") || infoDocu.trim().equals(""))
z = "Por favor digite um nome e um documento";
else{
try{
Connection con = connectionClass.CONN();
if (con == null){
z = "Erro na conexão com o Banco de Dados";
}
else
{
String query = "insert into usuarios (nome,endereco) values ('" + infoName + "','" +infoDocu + "')";
PreparedStatement preparedStatement = con.prepareStatement(query);
preparedStatement.executeUpdate();
z = "Cadastro inserido com sucesso";
isSucess = true;
}
}catch( Exception ex){
isSucess = false;
z = "Exceptions";
}
}
return z;
}
}
@SuppressLint("NewApi")
public Connection connectionclass (String user, String password, String database, String server)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = null;
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnectionURL = "jdbc:jtds:sqlserver://192.168.0.169/ANDROID_SQL;instance=MEGACONTROL;user=sa;password=@dm1n102030";
//ConnectionURL = "jdbc:jtds:sqlserver://" + ip +"/"+ db +";""istance=MEGACONTROL""";user=" + un + ";password="+ password + ";";
connection = DriverManager.getConnection(ConnectionURL);
} catch (ClassNotFoundException e) {
e.printStackTrace();
Log.e("Error here 1", e.getMessage());
} catch (SQLException e) {
e.printStackTrace();
Log.e("Error here 2", e.getMessage());
}
return connection;
}
}