I have the right IP:Port, so I don't know where is the problem, since communicationsexception comes from broken url:port for the mysql database.
package com.bbb.aaa;
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.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final String url = "jdbc:mysql://uk1.khttp.net:2083/thedatabase"; // uk1.khttp.net == 95.154.195.28
private static final String user = "theusername";
private static final String pass = "thepassword";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("About to try instantiating driver");
TextView tv = (TextView)this.findViewById(R.id.text_view);
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.print("success");
Connection con = DriverManager.getConnection(url, user, pass);
String result = "Database connection success\n";
System.out.print("success2");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM testingregistration");
System.out.print("success3");
ResultSetMetaData rsmd = rs.getMetaData();
while(rs.next()) {
result += rsmd.getColumnName(1) + ": " + rs.getInt(1) + "\n";
result += rsmd.getColumnName(2) + ": " + rs.getString(2) + "\n";
result += rsmd.getColumnName(3) + ": " + rs.getString(3) + "\n";
}
tv.setText(result);
tv.setText("Driver instantiated");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
tv.setText(".....Class com.mysql.jdbc.Driver not found!");
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tv.setText(e.toString());
}
}
}
ERROR LOG: The last packet sent successfuly to the server was 0 milliseconds ago. The driver has not recieved any packets from the server
The console reads and prints "success" but then it crashes after that so it doesnt print "success2" meaning the problem is at connection.
I tried searching the internet for this problem but all they said was that your ip:port and database should be correct but for me this seems correct since I can use that url and port with the login and password details to login to the mysql and then from there I click phpMyAdmin and im in the database.
Thanks in advance