Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Connection conexionDB(){
- Connection conexion=null;
- try{
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
- conexion = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.1;databaseName=db;user=sa;password=12345");
- }catch (Exception e){
- }
- return conexion;
- }
- public void login(View v){
- try{
- txtUsuario = (EditText)findViewById(R.id.txtUsuario);
- txtClave = (EditText)findViewById(R.id.txtClave);
- PreparedStatement pst=conexionDB().prepareStatement("Select * From persona Where Usuario = ? And Clave = ?");
- pst.setString(1,txtUsuario.getText().toString());
- pst.setString(2,txtClave.getText().toString());
- ResultSet rs = pst.executeQuery();
- if(rs.next()){
- Toast.makeText(getApplicationContext(), "Acceso Correcto", Toast.LENGTH_SHORT).show();
- Intent Intent = new Intent(this, PrincipalActivity.class);
- startActivity(Intent);
- }else{
- Toast.makeText(getApplicationContext(), "Acceso Incorrecto", Toast.LENGTH_SHORT).show();
- }
- }catch (Exception e){
- Toast.makeText(getApplicationContext(), "Acceso Incorrecto", Toast.LENGTH_SHORT).show();
- }
- }
- Link :
- https://sourceforge.net/projects/jtds/files/latest/download?source=files
- https://www.youtube.com/watch?v=OOm03ezazAI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement