本文介绍了连接字符串形成为Android到SQLServer的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图2008R2数据库连接到SqlServer的蒙山Android系统。
这似乎不正确得到我的形成连接字符串。
我有以下错误:
My SqlInstance:
Connection String which i formed:
String dbName = "AndroidDB";
String serverip="10.0.2.2";
String serverport="1433";
String url = "jdbc:sqlserver://"+serverip+"\\14GRAFICALI\\MSSQLSERVER2008"+serverport+";databaseName="+dbName+"";
Whole Code in which i am implementing it:
public class MainActivity extends Activity {
String dbName = "AndroidDB";
String serverip="10.0.2.2";
String serverport="1433";
String url = "jdbc:sqlserver://"+serverip+"\\14GRAFICALI\\MSSQLSERVER2008"+serverport+";databaseName="+dbName+"";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvData=(TextView)findViewById(R.id.tvSelectedData);
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn =DriverManager.getConnection(url);
Statement statement=conn.createStatement();
ResultSet resultSet=statement.executeQuery("select * from UserMaster");
while(resultSet.next()){
tvData.setText(" Data1 : "+resultSet.getString(1)+" Data 2 : "+resultSet.getNString(2));
}
} catch (Exception e) {
e.printStackTrace();
tvData.setText(e.getMessage());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
解决方案
There are Few Steps That need to be foolwed in case when we are connecting Android to directly a SQLServer.
I have mentioned each and every detailed steps in my answer over here:
Class not found although particular jar is added in project
Please follow the stages and i am sure you will overcome all the errors.
这篇关于连接字符串形成为Android到SQLServer的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!