Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- private static final String url = "jdbc:mysql://<server>:<port>/<database>";
- private static final String user = "<username>";
- private static final String pass = "<password>";
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- testDB();
- }
- public void testDB() {
- TextView tv = (TextView)this.findViewById(R.id.text_view);
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(url, user,pass);
- String result = "Database connection successn";
- }
- tv.setText(result);
- }
- catch(Exception e) {
- e.printStackTrace();
- tv.setText(e.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement