Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. private static final String url = "jdbc:mysql://192.168.1.65:3306/myDB";
  4. private static final String user = "user";
  5. private static final String pass = "userpass";
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11. }
  12.  
  13. public void connect(View v){
  14. TextView tv = (TextView) findViewById(R.id.textView);
  15.  
  16. try{
  17. StrictMode.ThreadPolicy policy =
  18. new StrictMode.ThreadPolicy.Builder().permitAll().build();
  19. StrictMode.setThreadPolicy(policy);
  20.  
  21. Class.forName("com.mysql.jdbc.Driver");
  22. Connection con = DriverManager.getConnection(url,user,pass);
  23.  
  24. if(con!=null){
  25. tv.setText("Connection Successfully");
  26. }else
  27. tv.setText("FAAAAIL ");
  28.  
  29. }catch (Exception e){
  30. e.printStackTrace();
  31. tv.setText(e.toString());
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement