Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DBConnect extends AsyncTask<String, Void, Connection>
- {
- private Context ctx;
- SharedPreferences prefs;
- Connection conn;
- String ipValue;
- public DBConnect(Context ctx)
- {
- this.ctx=ctx;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- //get sharedPreferences here
- prefs = ctx.getSharedPreferences("DoorSystem_SHPREF",
- Context.MODE_PRIVATE);
- ipValue=prefs.getString("IP_VALUE",null);
- }
- @Override
- protected Connection doInBackground(String... params) {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
- .permitAll().build();
- StrictMode.setThreadPolicy(policy);
- String ConnURL = null;
- try {
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- ConnURL = "jdbc:jtds:sqlserver://" + ipValue + ":1433/doors;user=sam123;password=111";
- conn = DriverManager.getConnection(ConnURL);
- } catch (Exception se) {
- se.printStackTrace();
- }
- return conn;
- }
- }
- public void logIn(View view)
- {
- Toast.makeText(getApplicationContext(),ipValue,Toast.LENGTH_LONG).show();
- try {
- DBConnect dbConnect = new DBConnect(getApplicationContext());
- Connection conn=dbConnect.execute().get();
- LogInStatement="select count(*) from users where username=? AND password=?";
- preparedStatement=conn.prepareStatement(LogInStatement);
- preparedStatement.setString(1,userNameEditText.getText().toString());
- preparedStatement.setString(2,passwordEditText.getText().toString());
- ResultSet rs = preparedStatement.executeQuery();
- while (rs.next()) {
- count = rs.getInt(1);
- }
- if (count != 0) {
- Intent userScreenIntent = new Intent(this, UserScreen.class);
- startActivity(userScreenIntent);
- } else {
- Toast.makeText(getApplicationContext(), "بيانات الدخول غير صحيحة", Toast.LENGTH_LONG).show();
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement