我正在尝试显示实时/在线mysql数据库中的数据。所引用的代码链接是共享的,此代码在本地服务器上工作正常,但显示了实时服务器的异常
异常1(当提到url时):
拒绝访问用户'xxx'。@'nn.nn.nn.nn'(使用密码是)
异常2(使用端口号提及url时):
通信链接失败错误
对于本地服务器来说,相同的代码对我有用,但是我无法连接实时服务器。我已经更改了URL以及数据库,表名,但显示异常通信失败。 我已经看过这部影片
Android To MySql Database (Without JSON)
public class MainActivity extends Activity {
public static final String url = "jdbc:mysql://sg2plcpnl0174.prod.sin2.secureserver.net/xxx";
public static final String user = "xxxx";
public static final String pass = "xxxx";
在OnCreate方法()
中 try
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,user,pass);
String result = "Database connection success\n";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from table_name");
ResultSetMetaData rsmd = rs.getMetaData();
while(rs.next())
{
result += rsmd.getColumnName(1) + ": " + rs.getInt(1) + "\n";
result += rsmd.getColumnName(2) + ": " + rs.getInt(2) + "\n";
result += rsmd.getColumnName(3) + ": " + rs.getInt(3) + "\n";
result += rsmd.getColumnName(4) + ": " + rs.getInt(4) + "\n";
result += rsmd.getColumnName(5) + ": " + rs.getInt(5) + "\n";
result += rsmd.getColumnName(6) + ": " + rs.getInt(6) + "\n";
result += rsmd.getColumnName(7) + ": " + rs.getInt(7) + "\n";
}
tv.setText(result);
con.close();
}
预期结果:
android应用应显示mysql中的数据
Db实际结果:
异常错误