Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. Hi i am trying to connect JDBC data base using Android i have tried all the ways but i am getting error "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" in eclipse. I have added jar file also.Getting same exception. Will android does not support JDBC connection directly is my question.
  2.  
  3. private static final String url = "jdbc:mysql://<server>:<port>/<database>";
  4. private static final String user = "<username>";
  5. private static final String pass = "<password>";
  6. @Override
  7. public void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.main);
  10. testDB();
  11. }
  12. public void testDB() {
  13. TextView tv = (TextView)this.findViewById(R.id.text_view);
  14. try {
  15. Class.forName("com.mysql.jdbc.Driver");
  16. Connection con = DriverManager.getConnection(url, user,pass);
  17. String result = "Database connection successn";
  18. }
  19. tv.setText(result);
  20. }
  21. catch(Exception e) {
  22. e.printStackTrace();
  23. tv.setText(e.toString());
  24. }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement