Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. System.out.println("MySQL Connect Example.");
  2. Connection conn = null;
  3. String url = "jdbc:jtds:sqlserver://192.168.2.101:1433/INSERTGT";
  4. String dbName = "podmiot";
  5. String driver = "net.sourceforge.jtds.jdbc.Driver";
  6.  
  7.  
  8. String userName = "user";
  9. String password = "pass";
  10. try {
  11. Class.forName(driver).newInstance();
  12. conn = DriverManager.getConnection(url+dbName,userName,password);
  13. System.out.println("Connected to the database");
  14. int duration = Toast.LENGTH_SHORT;
  15.  
  16.  
  17. Toast.makeText(getApplicationContext(), "Connected to the database", duration);
  18.  
  19. conn.close();
  20. System.out.println("Disconnected from database");
  21. EditText edit1 = (EditText)findViewById(R.id.editText1);
  22. edit1.setText("Disconnected from database");
  23.  
  24. } catch (Exception e) {
  25. e.printStackTrace();
  26. TextView edit1 = (TextView)findViewById(R.id.exception);
  27. edit1.setText("Problem: " + e.toString());
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement