我是 Android 应用程序的新手。开发,我正在尝试开发一个应用程序。可以通过 jtds 达到 ms sql 2008 r2。
我已经使用 sqllite 数据库来创建连接字符串。
我收到android os.NetworkOnMainThreadException
错误,请帮助我,我的代码如下,
private void giris() {
DB db = new DB(this);
db.open();
Cursor c = db.Query();
String ipAdresi = null, Port = null, veriTabaniAdi = null, kullaniciAdi = null, sifre = null;
while (c.moveToNext()) {
ipAdresi = c.getString(c.getColumnIndex("IpAdresi"));
Port = c.getString(c.getColumnIndex("PORT"));
kullaniciAdi = c.getString(c.getColumnIndex("KullaniciAdi"));
sifre = c.getString(c.getColumnIndex("Sifre"));
}
url = "jdbc:jtds:sqlserver://" + ipAdresi + ":" + Port + ";databaseName=";
driver = "net.sourceforge.jtds.jdbc.Driver";
userName = kullaniciAdi;
password = sifre;
db.close();
ResultSet results = null;
try {
EditText txtTest = (EditText)findViewById(R.id.editTextip);
EditText txtName = (EditText)findViewById(R.id.editTextport);
String user = txtTest.getText().toString();
String pass = txtName.getText().toString();
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url, userName, password);
Statement statement = conn.createStatement();
results = statement.executeQuery("Select * From Kullanıcı where KULLANICI = '" + user + "' and SIFRE = '"+ pass + "'");
if(!results.next())
{
Toast.makeText(this, "Hoşgeldiniz ", Toast.LENGTH_SHORT).show();
try {
Class d = Class.forName("com.example.endustrinetbistro.Girismenu");
Intent intent = new Intent(this, d);
startActivity(intent);
} catch (ClassNotFoundException e) {
Toast.makeText(this, "Hata : " + e.toString(),
Toast.LENGTH_SHORT).show();
}
}
else
{
do{
Toast.makeText(this, "Hata : " + "Kullanıcı Adınız, Şifreniz veya Baglantı Ayarlarınızda Bir Sorun var ", Toast.LENGTH_SHORT)
.show();
}while(results.next());
}
} catch (Exception e) {
Toast.makeText(this, "Hata : " + e.toString(), Toast.LENGTH_SHORT)
.show();
}
}
}