try {
String url = "jdbc:sqlserver://Aman\\SQL12;databaseName=P2C_Android";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url, "sa", "aman");
String sql =
"select * from UserTable " +
"where username='" + username.getText().toString() +
"' and password='" + password.getText().toString() + "'";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
if (rs != null && rs.next())
Toast.makeText(getApplicationContext(), "Redirecting...",
Toast.LENGTH_SHORT).show();
else {
Toast.makeText(getApplicationContext(), "Wrong Credentials",
Toast.LENGTH_SHORT).show();
attempts.setBackgroundColor(Color.RED);
counter-- ;
attempts.setText(Integer.toString(counter));
if(counter == 0)
login.setEnabled(false);
}
}
catch (Exception ex) {
Toast.makeText(getApplicationContext(),
ex.getMessage(), Toast.LENGTH_SHORT).show();
}
即使我可以看到sqljdbc.jar
我添加的类存在,它也说找不到类。
我正在尝试从 android 应用程序访问数据库。