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());
} 
3
  • 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. Commented Aug 18, 2013 at 15:23
  • There are many ways of implementing a server for your android app. jersey.java.net makes it pretty easy to expose RESTful services. Commented Aug 18, 2013 at 17:20
  • see this answer stackoverflow.com/questions/10679588/… Commented Aug 20, 2013 at 21:51

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.