我做了一个非常简单的应用程序只是为了稳定与我的SQL数据库在Raspberry Pi上的连接与JDBC,但当我尝试连接时,应用程序给我一个错误,任何建议?
代码:
public class MainActivity extends AppCompatActivity {
private static final String url = "jdbc:mysql://192.168.1.65:3306/myDB";
private static final String user = "user";
private static final String pass = "userpass";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void connect(View v){
TextView tv = (TextView) findViewById(R.id.textView);
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);
if(con!=null){
tv.setText("Connection Successfully");
}else
tv.setText("FAAAAIL ");
}catch (Exception e){
e.printStackTrace();
tv.setText(e.toString());
}
}
}