2014-12-25 73 views
0

我想在本地主機上開發一個新的android應用程序(java),並且我想讓用戶在部署應用程序後將他的服務器地址ip放入應用程序中。 這裏的連接梅索德如何在java中獲得服務器地址ip dynamiclly

public class connexiondb { 
 
\t @SuppressLint("NewApi") 
 
\t protected Connection getConnection(){ 
 
\t \t StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
 
\t \t StrictMode.setThreadPolicy(policy); 
 
\t \t Connection conn=null; 
 
     String connURL; 
 
     try { 
 
\t \t \t Class.forName("net.sourceforge.jtds.jdbc.Driver"); 
 
\t \t \t connURL="jdbc:jtds:sqlserver://localhost:1433;databaseName=idmaj;user=youssef;password=azerty" ; 
 
\t \t \t conn=DriverManager.getConnection(connURL); \t \t \t \t 
 
\t \t \t //conn.close(); 
 
     } catch (SQLException e) { 
 
\t \t \t Log.e("ERROR",e.getMessage()); 
 
\t \t }catch (ClassNotFoundException e) { 
 
\t \t \t Log.e("ERROR",e.getMessage()); 
 
\t \t }catch (Exception e) { 
 
\t \t \t Log.e("ERROR",e.getMessage()); 
 
\t \t } 
 
     return conn; 
 
\t } 
 

 
}

+0

什麼問題? –

+0

我想允許用戶在部署應用程序後將他的服務器地址ip放入應用程序中。 – estemEvent

回答

1

,你堅持的IP只需使用一個配置文件。 提供一個用戶可以輸入URI並保存在配置文件中的屏幕。 在實例化客戶端時,請閱讀新URI的配置文件。