Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6090191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:11:11+00:00 2026-05-23T12:11:11+00:00

String[] items = new String[10]; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //

  • 0
String[] items = new String[10];
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create a variable for the connection string.
      String connectionUrl = "jdbc:sqlserver://servername.database.windows.net;" +
          "databaseName=School;user=username@servername;password=userpassword"; 

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

    setListAdapter(new ArrayAdapter<String>(this,
                                            android.R.layout.list_item,
                                            new ArrayList()));

    new AddStringTask().execute();

    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 dbo.tbl";
         stmt = con.createStatement();
         rs = stmt.executeQuery(SQL);

         // Iterate through the data in the result set and display it.
         while (rs.next()) {
                String items = rs.getArray(2) + " " + rs.getArray(3);
         }
      }

      // 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) {}
      }
}

class AddStringTask extends AsyncTask<Void, String, Void> {
    @Override
    protected Void doInBackground(Void... unused) {

        return(null);
    }

    @Override
    protected void onProgressUpdate(String... item) {
        ((ArrayAdapter)getListAdapter()).add(item[0]);
    }

    @Override
    protected void onPostExecute(Void unused) {
        Toast
            .makeText(AsyncDemo.this, "Done!", Toast.LENGTH_SHORT)
            .show();
    }
}

In the while loop inside onCreate I would like to get 10 rows and 2 columns from the table in the remote database which is sql azure then store it in a string array. Then that string array gets outputted to the user as a list view. JDBC driver download link min.bz/wC4Am (Non-Windows users get compressed file. The last one listed)Also updated the link.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:11:11+00:00Added an answer on May 23, 2026 at 12:11 pm

    Android-Java-SQLAzure good combination, congrats!

    On the other hand, why do you access database (SQL Azure) directly from mobile app? This has a few drawbacks:

    • You need to include SQL Server adapter and JDBC libraries on mobile application, which is gonna take at least 1 MB in size.
    • Your app users will be able to see your database password with a few tricks. This is a big security vulnerability for your system! Users can even drop your tables.
    • Mobile apps (especially Android) should not be preferred to consume database directly (since Android activity cycle policy, apps can pause for some time and your database connection might be dropped meanwhile, and you get various unexpected exceptions due this reason.).

    Therefore you should create a web service or REST API with Java or ASP.NET which you can execute your queries through this proxy and gives you results back in a JSON, or XML or a good format that Java can easily parse and adapt your ArrayAdapter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have classX: Sub New(ByVal item_line_no As String, ByVal item_text As String) ' check
I have a regular control in my code with several items. <mx:List id=myList> <mx:String>Item
I'm new to using the PreferenceActivity. Task: Allow user to choose the program layout
I have a main menu with an action bar. On create, I run a
I want to create a listview populated with items I have transferred to this
I need to iterate through the items (strings) in a CComboBox to check which
I have a dictionary of 200,000 items (the keys are strings and the values
In my base page I need to remove an item from the query string
I have a label function like : private function formatDate (item:Object, column:DataGridColumn):String { var
Using SQL Server, how do I split a string so I can access item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.