附上源代码:
public class MainActivity extends Activity {
private Button btn;
private TextView showTV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.btn);
showTV = (TextView) findViewById(R.id.showTV);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String str = linkSQL();
showTV.setText(str);
}
});
}
private String linkSQL() {
String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=my_data";
String USER = "sa";
String PWD = "123456";
String result = null;
try {
Class.forName(DRIVER);
Connection conn = DriverManager.getConnection(URL, USER, PWD);
result = "succeed";
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println(e.toString());
result = e.toString();
} catch (SQLException e) {
e.printStackTrace();
System.out.println(e.toString());
result = e.toString();
}
return result;
}
}
这就是源代码,架包添加对了的,直接从数据库管理软件也能连接上数据库,架包下也能找到SQLServerDriver.class这个类,就是一直报这个错误,求各位大神帮帮忙。