【发布时间】:2013-09-10 10:16:12
【问题描述】:
我正在做 SqlServer2008 r2 与 android 的连接。
我的代码如下:
public class MainActivity extends Activity {
String url="jdbc:sqlserver://localhost;instance=14GRAFICALI\\MSSQLSERVER2008;databaseName=AndroidDB;integrated security=true";
@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);
System.out.println("connected");
Statement statement=conn.createStatement();
ResultSet resultSet=statement.executeQuery("select * from AndroidDB");
while(resultSet.next()){
tvData.setText(" Data1 : "+resultSet.getString(1)+" Data 2 : "+resultSet.getNString(2));
}
} catch (Exception e) {
e.printStackTrace();
}
}
此代码不起作用,并在线给我错误:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
错误:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
但是当我检查这个路径时,文件在上面的路径中。
看看吧:
可能是什么问题?
请帮帮我。
编辑
Javabuildpath:
库:
【问题讨论】:
-
你能在你的项目属性中发布一个java构建路径的屏幕吗?
-
@OnurA。先生请看一下
-
本地主机应该是
10.0.2.2 -
@SunilMishra 先生,但其中没有涉及网络服务?还可以吗?
-
你是不是也在libs文件夹中添加了jar文件??