从android(java)连接到SQL Server 2008数据库

从android(java)连接到SQL Server 2008数据库,java,android,sql-server-2008,jdbc,Java,Android,Sql Server 2008,Jdbc,我有以下代码,它没有到达.setText(“Successful”)语句,这表明drivermanager.getConnectionStateMenet(我认为)存在问题。它从net.sourceforge查找我正在使用的数据库驱动程序。但是没有抛出异常错误消息,没有发生任何事情: String connectionurl = "jdbc:jtds:sqlserver://41.185.13.201; databaseName=Courses; user=*;Password=

我有以下代码,它没有到达.setText(“Successful”)语句,这表明drivermanager.getConnectionStateMenet(我认为)存在问题。它从net.sourceforge查找我正在使用的数据库驱动程序。但是没有抛出异常错误消息,没有发生任何事情:

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

您应该通过web服务(JAX-WS或JAX-RS)访问数据。这是您可以使用的最佳体系结构。如上所述,您只需开发一个中间件。

您可能应该在所有catch子句中打印异常。从Android应用程序直接连接到数据库是一个非常糟糕的设计,实现一些中间件。有很多方法可以为Android应用程序实现服务器。使公开RESTful服务变得非常容易