2014-04-16 6 views
1

안드로이드 앱을 mssql 데이터베이스에 연결하려고합니다. 하지만 연결을 시도 할 때 예외가 생겼습니다. 디버그 모드에서 체크하고 예외 캐치 여기에 내 코드가 있습니다.안드로이드 앱에 mssql 연결

protected void onStart() { 
    try 
    { 
     // Load the SQLServerDriver class, build the 
     // connection string, and get a connection 
     Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
     String connectionUrl = "jdbc:sqlserver://xxx\\xxxxx:1433;" + 
           "database=xxxx;" + 
           "user=xxxx;" + 
           "password=*****"; 
     Connection con = DriverManager.getConnection(connectionUrl); 
     System.out.println("Connected."); 

     // Create and execute an SQL statement that returns some data. 
     String SQL = "SELECT COUNT(*) FROM xxxxxx"; 
     Statement stmt = con.createStatement(); 
     ResultSet rs = stmt.executeQuery(SQL); 
     TextView tv=(TextView) findViewById(R.id.textView1); 
     tv.setText((CharSequence) rs); 


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


    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    super.onStart(); 
} 

답변

0

Android는 대역폭의 한계로 인해 외부 데이터베이스와 통신 할 수 없지만 MySQL에서 필요로하는 것을 반환하는 간단한 웹 페이지 (php)를 만드는 것이 가능합니다. 데이터베이스를 분석하고 XML 파일 또는 JSON으로 구문 분석하면 안드로이드 응용 프로그램에서이 PHP 페이지를 호출하고 JSON 파일을 얻을 수 있습니다.

이것은 TUTO 아주 잘 설명되어

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

행운을 빕니다 :)

0

그런 Android 앱에서 MSSQL에 연결할 수 없습니다. 데이터베이스 요청을 처리 할 웹 서비스를 만들어야합니다. 그런 다음 해당 웹 서비스를 앱에서 호출 할 수 있습니다.