0

I using "com.microsoft.sqlserver.jdbc.SQLServerDriver" to conmect to Microsoft Azure, The code working in Java Project, And not working in Java Android Project.

The code:

        String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
            "databaseName=AdventureWorks;integratedSecurity=true;";

        // Declare the JDBC objects.
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;

            try {
                // Establish the connection.
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                    con = DriverManager.getConnection(connectionUrl);

                    // Create and execute an SQL statement that returns some data.
                    String SQL = "SELECT TOP 10 * FROM Person.Contact";
                    stmt = con.createStatement();
                    rs = stmt.executeQuery(SQL);

                    // Iterate through the data in the result set and display it.
                    while (rs.next()) {
                        System.out.println(rs.getString(4) + " " + rs.getString(6));
                    }
            }

        // Handle any errors that may have occurred.
        catch (Exception e) {
            e.printStackTrace();
        }

        finally {
            if (rs != null) try { rs.close(); } catch(Exception e) {}
                if (stmt != null) try { stmt.close(); } catch(Exception e) {}
                if (con != null) try { con.close(); } catch(Exception e) {}
        }

This is the Java Project: enter image description here

And this is the Android Project with the error window: enter image description here

THANKS

  • You are attempting to get `com.microsoft.sqlserver.jdbc.SQLServerDriver`, and there is no such class in your Android app. What have you tried to do to add it to your app? Also note that using JDBC from a mobile app is not considered to be a very good idea. – CommonsWare Dec 06 '16 at 17:28
  • Why you shouldn't try to use JDBC with Android: http://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android – Morrison Chang Dec 06 '16 at 17:46
  • Thank you very much – Ahmad Egbaria Dec 06 '16 at 19:08
  • Please don't use screenshots (and especially not photo's of your screen), post the code and error as **text**. AFAIK you can't just use Java libraries for Android, and accessing a database directly from Android is a bad idea anyway: use a REST service as intermediary. – Mark Rotteveel Dec 07 '16 at 08:12

0 Answers0