Good, I am developing an app in Android Studio and it fails to make the connection to the remote database (I know it gives an error there because it catches the catch and does not pass that line when running the program).
My problem is that I can not find where the failure is, although I imagine that it will be something related to the ip of the server where I have the database. I have tried with the ip put with numbers, with letters, I have seen that the port is good and several things more.
I attach the Java code:
Button btn;
EditText et;
Connection con;
String prueba, un, pass, db, ip;
Statement stt;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button);
et = (EditText) findViewById(R.id.editText);
//ip = "145.14.144.52";
t = findViewById(R.id.textView);
t.setVisibility(View.INVISIBLE);
db = "id3001279_unasproofs";
ip = "jdbc:mysql://000webhost.com:3306/"+db;
un = "id3001279_unasproofs";
pass = "******";
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
prueba = et.getText().toString();
try {
Class.forName("com.mysql.jdbc.Driver");
//.newInstance();
con = (Connection) DriverManager.getConnection(ip, un, pass);
stt = con.createStatement();
String query = "INSERT INTO txumino VALUES(" +et.getText().toString() + ");";
ResultSet rs = stt.executeQuery(query);
}catch (Exception e){
t.setVisibility(View.VISIBLE);
}
}
});
}
I have put the password with "*" for the security of my database. The same database has a single table called txumino where there is a column that is VARCHAR.
Finally add that the interfaces are simple. It is an EditText with a button below that what it would do would be to insert in the database the value entered in that field (EditText).
Logcat error: D / ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
Greetings.