barnacle.m
barnacle.m

Reputation: 2190

Connecting to SQL Server 2008 database from android (java)

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());
} 

Upvotes: 0

Views: 1082

Answers (1)

Harry Coder
Harry Coder

Reputation: 2730

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.

Upvotes: 1

Related Questions