我添加了网络权限,并将jtds-1.3.1.jar添加到libs driectory。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
但是当我得到getConnection时,它会在DriveManager.getConnection上出现异常消息(android.os.NetworkOnMainThreadException)。有人知道我输了什么吗?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViews();
}
private void findViews()
{
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
con = DriverManager.getConnection(URL, USER, PASSWORD);
}
catch (Exception e)
{
Log.w("Error connection","" + e.getMessage());
}