0

I have the following code, which does not get to the .setText("Successful") statement, indicating an issue with the drivermanager.getConnection statemenet (I think). It finds the database driver that I'm using from net.sourceforge. But there is no exception error message thrown, nothing happens:

        String connectionurl = "jdbc:jtds:sqlserver://41.185.13.201; databaseName=Courses; user=*;Password=*;Persist Security Info=True;";
try {
        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();

        Connection con = DriverManager.getConnection(connectionurl);
        textview7.setText("Successful");
        // Create and execute an SQL statement that returns some data.
        String SQL = "INSERT INTO Courses (CourseCode) VALUES ('INFO3002')";
        Statement stmt = con.createStatement();
        stmt.executeUpdate(SQL);
        con.close();
} 

    catch (ClassNotFoundException e) {

         textview7.setText("Could not find the database driver " + e.getMessage());

               } catch (SQLException e) {          
                   textview7.setText("Could not connect to the database " + e.getMessage());

               }

catch (Exception e) {
    //textview7.setText(e.getMessage());
} 
barnacle.m
  • 2,070
  • 3
  • 38
  • 82
  • 1
    You should probably print the exception in all of your catch clauses. Connecting directly to a database from an Android application is a really bad design, implement some middleware. – samlewis Aug 18 '13 at 15:23
  • There are many ways of implementing a server for your android app. http://jersey.java.net makes it pretty easy to expose RESTful services. – samlewis Aug 18 '13 at 17:20
  • see this answer http://stackoverflow.com/questions/10679588/android-access-to-remote-sql-database/10682780#10682780 – Namphibian Aug 20 '13 at 21:51

1 Answers1

1

You should access your data through web services (JAX-WS or JAX-RS). It is the best architecture you can use. As said above, you should simply develop a middleware.

Harry Coder
  • 2,429
  • 2
  • 28
  • 32