Please help, I don’t know what’s wrong with this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Connection conn = null;
Statement state = null;
TextView t = findViewById(R.id.balls);
t.setText("ayaw");
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://walwalan-wryxth.c.aivencloud.com:21133/defaultdb", "XXXXX",
"XXXXX");
t.setText("SUCCESSSSSSSS");
} catch (ClassNotFoundException e) {
e.printStackTrace();
t.setText("Class " + e.toString());
} catch (SQLException e) {
e.printStackTrace();
t.setText("SQL " + e);
} finally {
try {
if (state != null)
state.close();
if (conn != null)
state.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
The error I get is java.sql.SQLNonTransientConnectionException
.
I know the database is on because i tried to connect to using MySQL viewer app.
I also doubled check the url, username, and password. also added internet permission.
I could send you the username and password if it’s needed.
I’m also new at coding and I’m only coding on my Android app.
Thank you!!!
Yelrah Tej is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.