我在 Android 中进行 SqlServer 连接。
我包含了所有必要的 jar 文件。
构建路径快照:
错误行:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
订购和出口:
编辑
package com.example.sqlservercall;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
String url="jdbc:sqlserver://10.0.2.2;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();
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;
}
}
异常详细:
按顺序检查罐子并导出后的新错误:
Unable to execute dex: Multiple dex files define Lcom/microsoft/sqlserver/jdbc/ActivityCorrelator$1;
[2013-09-06 18:24:04 - SQLServerCall] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/microsoft/sqlserver/jdbc/ActivityCorrelator$1;
[2013-09-06 18:24:23 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/microsoft/sqlserver/jdbc/ActivityCorrelator$1;
[2013-09-06 18:24:23 - SQLServerCall] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/microsoft/sqlserver/jdbc/ActivityCorrelator$1;